blob: df35335d47d64c351575da36b37d452fae93570d [file] [log] [blame]
Sybren A. Stüvel2310b342016-01-22 13:11:22 +01001"""
2Some tests for the rsa/key.py file.
3"""
4
5
6import unittest
7
8import rsa.key
9import rsa.core
10
11
12class BlindingTest(unittest.TestCase):
13
14 def test_blinding(self):
15 """Test blinding and unblinding.
16
17 This is basically the doctest of the PrivateKey.blind method, but then
18 implemented as unittest to allow running on different Python versions.
19 """
20
21 pk = rsa.key.PrivateKey(3727264081, 65537, 3349121513, 65063, 57287)
22
23 message = 12345
24 encrypted = rsa.core.encrypt_int(message, pk.e, pk.n)
25
26 blinded = pk.blind(encrypted, 4134431) # blind before decrypting
27 decrypted = rsa.core.decrypt_int(blinded, pk.d, pk.n)
28 unblinded = pk.unblind(decrypted, 4134431)
29
30 self.assertEqual(unblinded, message)