Sybren A. Stüvel | 2310b34 | 2016-01-22 13:11:22 +0100 | [diff] [blame^] | 1 | """ |
| 2 | Some tests for the rsa/key.py file. |
| 3 | """ |
| 4 | |
| 5 | |
| 6 | import unittest |
| 7 | |
| 8 | import rsa.key |
| 9 | import rsa.core |
| 10 | |
| 11 | |
| 12 | class 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) |