Ejemplo n.º 1
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.º 2
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.º 3
0
 def test_native_encrypt_python_decrypt(self):
     c = native.CryptEncrypt(self.hkey, TEST_DATA)
     p2 = self.python_key.decrypt(c)
     self.assertEqual(TEST_DATA, p2)
Ejemplo n.º 4
0
 def test_native_import_crypt_decrypt(self):
     c = native.CryptEncrypt(self.hkey, TEST_DATA)
     p2 = native.CryptDecrypt(self.hkey, c)
     self.assertEqual(TEST_DATA, p2)