Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
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
Exemplo n.º 6
0
 def _decipher(self, cipher_text):
     rsa_oaep_decrypt(self.key[1], cipher_text)