def test08(self): print 'test08-------------------------' # en-- key = 'Call me Ishmael.'[:16] key = map(ord, key) data = 'This is not a block length.' mode = aes.AESModeOfOperation.modeOfOperation["CBC"] if mode == aes.AESModeOfOperation.modeOfOperation["CBC"]: data = aes.append_PKCS7_padding(data) keysize = len(key) assert keysize in aes.AES.keySize.values( ), 'invalid key size: %s' % keysize # create a new iv using random data iv = [12, 34, 96, 15, 12, 34, 96, 15, 12, 34, 96, 15, 12, 34, 96, 15] moo = aes.AESModeOfOperation() (mode, length, ciph) = moo.encrypt(data, mode, key, keysize, iv) # With padding, the original length does not need to be known. It's a bad # idea to store the original message length. # prepend the iv. encrypt_data = ciph print aes.decryptDataIv(key, ciph, iv) keysize = len(key) assert keysize in aes.AES.keySize.values( ), 'invalid key size: %s' % keysize # iv is first 16 bytes #iv = map(ord, encrypt_data[:16]) moo = aes.AESModeOfOperation() decr = moo.decrypt(encrypt_data, None, mode, key, keysize, iv) if mode == aes.AESModeOfOperation.modeOfOperation["CBC"]: decr = aes.strip_PKCS7_padding(decr) print decr
def test08(self): print 'test08-------------------------' # en-- key = 'Call me Ishmael.'[:16] key = map(ord, key) data = 'This is not a block length.' mode = aes.AESModeOfOperation.modeOfOperation["CBC"] if mode == aes.AESModeOfOperation.modeOfOperation["CBC"]: data = aes.append_PKCS7_padding(data) keysize = len(key) assert keysize in aes.AES.keySize.values(), 'invalid key size: %s' % keysize # create a new iv using random data iv = [12, 34, 96, 15, 12, 34, 96, 15, 12, 34, 96, 15, 12, 34, 96, 15] moo = aes.AESModeOfOperation() (mode, length, ciph) = moo.encrypt(data, mode, key, keysize, iv) # With padding, the original length does not need to be known. It's a bad # idea to store the original message length. # prepend the iv. encrypt_data = ciph print aes.decryptDataIv(key, ciph, iv) keysize = len(key) assert keysize in aes.AES.keySize.values(), 'invalid key size: %s' % keysize # iv is first 16 bytes #iv = map(ord, encrypt_data[:16]) moo = aes.AESModeOfOperation() decr = moo.decrypt(encrypt_data, None, mode, key, keysize, iv) if mode == aes.AESModeOfOperation.modeOfOperation["CBC"]: decr = aes.strip_PKCS7_padding(decr) print decr
def testAesSha256de(self): password = '******' sha = hashlib.sha256() sha.update(password) dm = sha.digest() key = str2nums(dm) md5 = hashlib.md5() md5.update(password) iv = str2nums(md5.digest()) enhex = 'bda7fe34586e7297a661ba30b2df27d05e54fb579224ab5d1f6bbc11ec330d01' endata = hex2ls(enhex) plaintext = aes.decryptDataIv(key, endata, iv) print plaintext pass