def test_AES(self): key = a2b_hex("c286696d887c9aa0611bbb3e2025a45a") IV = a2b_hex("562e17996d093d28ddb3ba695a2e6f58") plaintext = a2b_hex("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f") ciphertext = a2b_hex("d296cd94c2cccf8a3a863028b5e1dc0a7586602d253cfff91b8266bea6d61ab1") assert(AES(key, IV).encrypt(plaintext) == ciphertext) assert(AES(key, IV).decrypt(ciphertext) == plaintext)
def test_AES(self): key = a2b_hex( "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4") IV = a2b_hex("000102030405060708090A0B0C0D0E0F") plaintext = a2b_hex("6bc1bee22e409f96e93d7e117393172a") ciphertext = a2b_hex("f58c4c04d6e5f1ba779eabfb5f7bfbd6") assert (AES.create(key, IV).encrypt(plaintext) == ciphertext) assert (AES.create(key, IV).decrypt(ciphertext) == plaintext)
def _encrypt(self, password): encKey, authKey = self._deriveKeys(password, self.salt, self.iter_count) ciphertext = AES.create(encKey, bytearray(16)).encrypt(self.private_key.getRawKey()) macData = ciphertext + self.public_key.getRawKey() mac = Digest.HMAC_SHA256(authKey, macData) self.ciphertext = ciphertext self.mac = mac
def _encryptKey(self, password, salt, iter_count, public_key, private_key): encKey, authKey = self._deriveKeys(password, salt, iter_count) ciphertext = AES(encKey, bytearray(16)).encrypt(private_key.getRawKey()) macData = ciphertext + public_key.getRawKey() mac = Digest.HMAC_SHA256(authKey, macData) return ciphertext, mac
def _encrypt(self, password): encKey, authKey = self._deriveKeys(password, self.salt, self.iter_count) ciphertext = AES.create(encKey, bytearray(16)).encrypt( self.private_key.getRawKey()) macData = ciphertext + self.public_key.getRawKey() mac = Digest.HMAC_SHA256(authKey, macData) self.ciphertext = ciphertext self.mac = mac
def _decrypt(self, password): encKey, authKey = self._deriveKeys(password, self.salt, self.iter_count) macData = self.ciphertext + self.public_key.getRawKey() calcMac = Digest.HMAC_SHA256(authKey, macData) if not Util.constTimeCompare(calcMac, self.mac): raise InvalidPasswordException("Bad password") return AES.create(encKey, bytearray(16)).decrypt(self.ciphertext)