MCPcopy Create free account
hub / github.com/ELMERIKH/PyinMemoryPE / decrypt

Function decrypt

windows/crypto/encrypt_decrypt.py:95–119  ·  view source on GitHub ↗

Try to decrypt the ``encrypted`` msg with any certificate in ``cert_store``. If there is no certificate able to decrypt the message ``WinproxyError(winerror=0x8009200c)`` is raised. :param cert_store: :type cert_store: :class:`CertificateStore` :return: :class:`str`

(cert_store, encrypted)

Source from the content-addressed store, hash-verified

93
94
95def decrypt(cert_store, encrypted):
96 """Try to decrypt the ``encrypted`` msg with any certificate in ``cert_store``.
97
98 If there is no certificate able to decrypt the message ``WinproxyError(winerror=0x8009200c)`` is raised.
99
100 :param cert_store:
101 :type cert_store: :class:`CertificateStore`
102 :return: :class:`str`: The decrypted message
103 """
104 # Setup decryption parameters
105 dparam = CRYPT_DECRYPT_MESSAGE_PARA()
106 dparam.cbSize = ctypes.sizeof(dparam)
107 dparam.dwMsgAndCertEncodingType = DEFAULT_ENCODING
108 dparam.cCertStore = 1
109 dparam.rghCertStore = (cert_store,)
110 dparam.dwFlags = 0
111
112 #Ask the output buffer size
113 buf = (BYTE * len(encrypted)).from_buffer_copy(encrypted)
114 dcryptsize = DWORD()
115 winproxy.CryptDecryptMessage(dparam, buf, ctypes.sizeof(buf), None, dcryptsize, None)
116 #Decrypt the msg
117 dcryptbuff = (BYTE * (dcryptsize.value + 0x1000))()
118 winproxy.CryptDecryptMessage(dparam, buf, ctypes.sizeof(buf), dcryptbuff, dcryptsize, None)
119 return bytes(bytearray(dcryptbuff[:dcryptsize.value]))

Callers

nothing calls this directly

Calls 2

from_buffer_copyMethod · 0.80
sizeofMethod · 0.45

Tested by

no test coverage detected