'Updated IV'
parent
a0dbc880a1
commit
601ca3a977
7
Core.py
7
Core.py
|
@ -68,7 +68,9 @@ def randomuri(size = 15, chars=string.ascii_letters + string.digits):
|
|||
# Decrypt a string from base64 encoding
|
||||
def get_encryption( key, iv='0123456789ABCDEF' ):
|
||||
from Crypto.Cipher import AES
|
||||
# print 'IV: ', iv
|
||||
print AES.block_size
|
||||
iv = os.urandom(AES.block_size)
|
||||
print iv
|
||||
aes = AES.new( base64.b64decode(key), AES.MODE_CBC, iv )
|
||||
return aes
|
||||
|
||||
|
@ -107,8 +109,9 @@ def encrypt( key, data, gzip=False ):
|
|||
if mod != 0:
|
||||
newlen = len(data) + (16-mod)
|
||||
data = data.ljust( newlen, '\0' )
|
||||
aes = get_encryption(key)
|
||||
aes = get_encryption(key, os.urandom(16))
|
||||
# print 'Data len: ' + str(len(data))
|
||||
print aes.IV
|
||||
data = aes.IV + aes.encrypt( data )
|
||||
if not gzip:
|
||||
data = base64.b64encode( data )
|
||||
|
|
|
@ -12,20 +12,21 @@ def encrypt( key, data, gzip=False ):
|
|||
f.write(data)
|
||||
data = out.getvalue()
|
||||
mod = len(data) % 16
|
||||
iv = os.urandom(16)
|
||||
if mod != 0:
|
||||
newlen = len(data) + (16-mod)
|
||||
data = data.ljust( newlen, '\0' )
|
||||
aes = get_encryption(key)
|
||||
aes = get_encryption(key, iv)
|
||||
ct = ""
|
||||
for i in xrange(0, len(data), 16):
|
||||
ct += aes.encrypt( data[i:i+16] )
|
||||
ct = '0123456789ABCDEF' + ct
|
||||
ct = iv + ct
|
||||
data = ct
|
||||
if not gzip:
|
||||
data = base64.b64encode( data )
|
||||
return data
|
||||
|
||||
def get_encryption( key, iv='0123456789ABCDEF' ):
|
||||
def get_encryption( key, iv ):
|
||||
aes = AESModeOfOperationCBC(base64.b64decode(key), iv = iv)
|
||||
return aes
|
||||
|
||||
|
|
Loading…
Reference in New Issue