4 Replies - 2202 Views - Last Post: 21 February 2012 - 11:53 AM Rate Topic: -----

#1 Nekroze  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Python Encryption

Posted 19 February 2012 - 09:25 AM

Ok I have a need to encrypt a file and then decrypt it and store it in ram for later use.

I would like to use blowfish as i have used it in the past and its as good as any, speed is a concern so i opted for c based and seemingly mature python encryption module called pycrypto (there was one i was looking at called py-bcrypt but it is very old and doesn't seem to install anymore) however the documentation for pycrypto is lacking in stuff that i need to get started, specifically with blowfish.

Also I will most likely be getting the file to decrypt out of a compressed folder so i need to be able to give the decrypt-er an actual file object not a file name, is this possible?

Also if you know of or use a better encryption module for python please share, i am not married to the idea of using blowfish i just want some thing that works and is simple.

EDIT: after looking for awhile, most of what i can find deals with encrypting/decrypting/hashing strings and passwords etc but not entire files... :sad3:

OFF-TOPIC (kinda): why is it that the library of python encryption modules seems so thin and lacking good, easy to use, and well maintained modules?

This post has been edited by Nekroze: 19 February 2012 - 11:26 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Python Encryption

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: Python Encryption

Posted 19 February 2012 - 11:46 AM

The first link in a Google search of "encrypting files with python" is not helpful?

And Googling "pyCrypto Blowfish" also brought up something helpful in the first link.
Was This Post Helpful? 0
  • +
  • -

#3 Nekroze  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: Python Encryption

Posted 19 February 2012 - 12:11 PM

i have actualy been looking at making the eli bendersky implementation work for me for a little bit now however i was hoping for more info on the blowfish part of it and while yes the google link for pycrypto blowfish may work it explains nothing.

Using the first link i may be able to get something working however i am unsure if its the best implementation for me where speed is important because i will be decrypting large files more often then not.
Was This Post Helpful? 0
  • +
  • -

#4 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: Python Encryption

Posted 21 February 2012 - 10:57 AM

PyCrypto is a great package, and the one that carries my recommendation. However, Blowfish was designed to be computationally difficult to brute force, which is implemented by an intentionally slow key schedule. If speed is your concern, AES would be a better candidate.

If you have code that is encrypting and decrypting strings, working on files is a simple process:
def save(filename, data):
    e_data = encrypt_string(data)
    f = open(filename, 'w')
    f.write(e_data)
    f.close()

def load(filename):
    f = open(filename)
    data = f.read()
    f.close()
    d_data = decrypt_string(data)
    return d_data


Was This Post Helpful? 0
  • +
  • -

#5 Nekroze  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 170
  • Joined: 08-May 11

Re: Python Encryption

Posted 21 February 2012 - 11:53 AM

thanks motoma, i have gone with AES and so far it seems good.

I have posted the code on how i used AES for this project, as it was not for text (often) over at my latest question/post here: http://www.dreaminco...ygame-question/

Thanks again for showing the way motoma, appreciated!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1