Ejemplo n.º 1
0
 def test_native_simplekeyblob(self):
     rsa_key = wincrypto.algorithms.RSA_KEYX.from_pem(TEST_RSA_PRIVATE_PEM)
     rsa_blob = wincrypto.api.CryptExportKey(rsa_key, None, bType_PRIVATEKEYBLOB)
     rsa_hkey = native.CryptImportKey(self.hprov, rsa_blob)
     for algorithm in symmetric_algorithms:
         instance = algorithm(b'A' * algorithm.key_len)
         blob = wincrypto.api.CryptExportKey(instance, rsa_key, bType_SIMPLEBLOB)
         hkey = native.CryptImportKey(self.hprov, blob, rsa_hkey)
         c = native.CryptEncrypt(hkey, TEST_DATA)
         p = instance.decrypt(c)
         native.CryptDestroyKey(hkey)
         self.assertEqual(TEST_DATA, p)
     native.CryptDestroyKey(rsa_hkey)
Ejemplo n.º 2
0
 def test_native_plaintextkeyblob(self):
     for algorithm in symmetric_algorithms:
         instance = algorithm('A' * algorithm.key_len)
         blob = wincrypto.api.CryptExportKey(instance, None, bType_PLAINTEXTKEYBLOB)
         hkey = native.CryptImportKey(self.hprov, blob)
         c = native.CryptEncrypt(hkey, TEST_DATA)
         p = instance.decrypt(c)
         native.CryptDestroyKey(hkey)
         self.assertEqual(TEST_DATA, p)
Ejemplo n.º 3
0
 def test_native_plaintextkeyblob(self):
     for algorithm in symmetric_algorithms:
         instance = algorithm(b'A' * algorithm.key_len)
         blob = wincrypto.api.CryptExportKey(instance, None, bType_PLAINTEXTKEYBLOB)
         hkey = native.CryptImportKey(self.hprov, blob)
         for key_param in [KP_ALGID, KP_KEYLEN]:
             native_val = native.CryptGetKeyParam(hkey, key_param)
             python_val = api.CryptGetKeyParam(instance, key_param)
             self.assertEqual(native_val, python_val)
         native.CryptDestroyKey(hkey)
Ejemplo n.º 4
0
 def setUp(self):
     self.hprov = native.CryptAcquireContext()
     self.hkey = native.CryptImportKey(self.hprov, TEST_RSA_PRIVATE_MSKEYBLOB)
     self.python_key = wincrypto.CryptImportKey(TEST_RSA_PRIVATE_MSKEYBLOB)