def _decrypt_user_password(self, encrypted): """ Attempts to decrypt the given password and returns it. """ cipher = AESCipher(self.secret_key) try: message = cipher.decrypt(encrypted) except ValueError: return None except TypeError: return None try: data = json.loads(message) except ValueError: return None return data.get('password', encrypted)
def test_aes_encrypt_decrypt(secret_key, original_msg): converted_secret_key = convert_secret_key(secret_key) cipher = AESCipher(converted_secret_key) encrypted_msg = cipher.encrypt(original_msg) assert cipher.decrypt(encrypted_msg) == original_msg
def test_aes_decrypt(secret_key, encrypted_msg, expected_msg): converted_secret_key = convert_secret_key(secret_key) cipher = AESCipher(converted_secret_key) decrypted_msg = cipher.decrypt(encrypted_msg) assert decrypted_msg == expected_msg