Package Editra :: Package src :: Module ed_crypt
[hide private]

Module ed_crypt

source code

This module provides utilities for encrypting and decrypting data. It is mostly used for saving passwords and other sensitive data in config files. The code in this file uses a fairly simple string transformation algorithm combined with a random salt for the encryption/decryption, and I also threw in a little code obfustication just for fun ;-).

USAGE:

Encrypt:

  1. Get the password string to encrypt
  2. Generate a new random salt with os.urandom() or some other randomly generated string for each password to use as an encryption key
  3. Encrypt the password by calling Encrypt(password, salt)
  4. Save the salt somewhere else
  5. Write out the encrypted password to your config file

Decrypt:

  1. Get the encrypted password string
  2. Get the associated salt
  3. Decrypt and get the orignal password by calling Decrypt(encrypted_passwd, salt)

EXAMPLE:

>>> salt = os.urandom(8)
>>> passwd = "HelloWorld"
>>> encrypted_passwd = Encrypt(passwd, salt)
>>> print encrypted_passwd
eNoNysERADAIArCVUAFx/8XauzyTqTEtdKEXoQIWCbCZjaM74qhPlhK4f+BVPKTTyQP7JQ5i
>>> decrypted_passwd = Decrypt(passwd, salt)
>>> print decrypted_passwd
HelloWorld

Finally: This message will self destruct in 5 seconds ...


Author: Cody Precord <cprecord@editra.org>

Functions [hide private]
 
_Encode(text) source code
 
_Decode(text) source code
 
Encrypt(passwd, salt)
Encrypt the given password string using the supplied salt as the cryptographic key.
source code
 
Decrypt(passwd, salt)
Decrypt the given password string using the supplied salt as a key If either the passwd or salt strings are empty the return value will be the same as the passwd parameter.
source code
Variables [hide private]
  __svnid__ = '$Id: ed_crypt.py 52855 2008-03-27 14:53:06Z CJP $'
  __revision__ = '$Revision: 52855 $'
Function Details [hide private]

Encrypt(passwd, salt)

source code 

Encrypt the given password string using the supplied salt as the cryptographic key. If either the passwd or salt strings are empty the return value will be the same as the passwd parameter.

Parameters:
  • passwd - String to encrypt
  • salt - key to encrypt string with

Decrypt(passwd, salt)

source code 

Decrypt the given password string using the supplied salt as a key If either the passwd or salt strings are empty the return value will be the same as the passwd parameter.

Parameters:
  • passwd - a non empty string
  • salt - a non empty string