'Updated IV'

chunking
benpturner 2018-09-02 20:08:53 +01:00
parent a0dbc880a1
commit 601ca3a977
2 changed files with 9 additions and 5 deletions

View File

@ -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 )

View File

@ -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