branch : pmacs2
This commit is contained in:
moculus 2008-03-14 03:51:52 +00:00
parent 170cafc10f
commit 13d488f440
2 changed files with 9 additions and 7 deletions

10
aes.py
View File

@ -4,6 +4,7 @@
import os, popen2
class Cipher:
'''Cipher represents a particular hashing strategy (password, seed, and type). Cipher can encrypt or decrypt data.'''
def __init__(self, password, seed='aes.py', hashtype='rmd160'):
self.password = password
self.seed = seed
@ -14,12 +15,13 @@ class Cipher:
return decrypt_data(encrypted, self.password, self.seed, self.hashtype)
def _check_aespipe():
'''This function checks if we have the "aespipe" binary in $PATH'''
result = os.system('which aespipe > /dev/null')
if result != 0:
raise Exception, "Could not find aespipe; is it installed?"
def encrypt_data(data, password, seed='aes.py', hashtype='rmd160'):
'''uses password to encrypt data'''
'''Uses password to encrypt data'''
_check_aespipe()
cmd = "aespipe -S '%s' -H '%s' -p 0" % (seed, hashtype)
(stdout, stdin, stderr) = popen2.popen3(cmd)
@ -33,14 +35,14 @@ def encrypt_data(data, password, seed='aes.py', hashtype='rmd160'):
return encrypted
def encrypt_path(path, data, password, seed='aes.py', hashtype='rmd160'):
'''uses password to encrypt data and writes result to path'''
'''Uses password to encrypt data and writes result to path'''
encrypted = encrypt_data(data, password, seed, hashtype)
f = open(path, 'w')
f.write(encrypted)
f.close()
def decrypt_data(encrypted, password, seed='aes.py', hashtype='rmd160'):
'''uses password to decrypt data'''
'''Uses password to decrypt data'''
_check_aespipe()
cmd = "aespipe -d -S '%s' -H '%s' -p 0" % (seed, hashtype)
(stdout, stdin, stderr) = popen2.popen3(cmd)
@ -62,7 +64,7 @@ def decrypt_data(encrypted, password, seed='aes.py', hashtype='rmd160'):
return data[:i]
def decrypt_path(path, password, seed='aes.py', hashtype='rmd160'):
'''uses password to decrypt data from path'''
'''Uses password to decrypt data from path'''
f = open(path, 'r')
encrypted = f.read()
f.close()