def test_rsa_private_oaep_decrypt(self): original_data = b'This is the message to sign' private = asymmetric.load_private_key(os.path.join(fixtures_dir, 'keys/test.key')) with open(os.path.join(fixtures_dir, 'rsa_public_encrypted_oaep'), 'rb') as f: plaintext = asymmetric.rsa_oaep_decrypt(private, f.read()) self.assertEqual(original_data, plaintext)
def test_rsa_oaep_encrypt(self): original_data = b'This is data to encrypt' private = asymmetric.load_private_key(os.path.join(fixtures_dir, 'keys/test.key')) public = asymmetric.load_public_key(os.path.join(fixtures_dir, 'keys/test.crt')) ciphertext = asymmetric.rsa_oaep_encrypt(public, original_data) self.assertIsInstance(ciphertext, byte_cls) plaintext = asymmetric.rsa_oaep_decrypt(private, ciphertext) self.assertEqual(original_data, plaintext)
async def message_detail(request): session = await get_session(request) user = await db.get_user(request.app, session['username']) message = await db.get_message(request.app, request.match_info['uuid'], user.uuid) try: decrypt = request.query['decrypt'] except KeyError: decrypt = False ret = {'user': session['username']} if 'username' in session else {} if decrypt: ret['text'] = asymmetric.rsa_oaep_decrypt( asymmetric.load_private_key( binascii.unhexlify(message.private_key.lstrip("\\x"))), binascii.unhexlify(message.ciphertext.lstrip("\\x"))) ret['message'] = message return ret
def _decipher(self, cipher_text): rsa_oaep_decrypt(self.key[1], cipher_text)