def test_invalid_enc_dec(self):
""" Check that we cannot unwrap a key using a private key that does
not correspond to the public key used to wrap the key.
"""
RSA_key = RSA.generate(3072)
RSA_pk = RSA_key.publickey()
for i in range(self.num_iters):
sk = format(random.getrandbits(128), 'b')
keywrap = wrap_key(sk, RSA_pk)
other_key = RSA.generate(3072)
try:
decrypted_key = unwrap_key(keywrap, other_key)
except ValueError:
self.assertTrue(True, 'error')
else:
self.assertNotEqual(decrypted_key, sk,
'Decryption succeeded with invalid key')
评论列表
文章目录