Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than msi, prefix the name with the module name and a period.
[StructLayout(LayoutKind.Sequential)]
public struct CERT_CONTEXT
{
public CertEncodingType dwCertEncodingType;
public IntPtr pbCertEncoded;
public uint cbCertEncoded;
public IntPtr pCertInfo;
public IntPtr hCertStore;
}
CERT_CONTEXT certContext = default;
try
{
// - First call gets the hash data buffer size.
// - Second call gets the hash data for real.
byte[] pbHashData = Array.Empty<byte>();
int pcbHashData = 0;
HRESULT hresult = HRESULT.E_MOREDATA;
for (int i = 0; i < 2 && hresult == HRESULT.E_MOREDATA; i++)
{
hresult = MsiGetFileSignatureInformation(
msiFilePath,
MSISIGINFO.MSI_INVALID_HASH_IS_FATAL,
ref pCertContext,
pbHashData,
ref pcbHashData);
if (hresult == HRESULT.E_MOREDATA)
{
// pbHashData is ready to use now.
pbHashData = new byte[pcbHashData];
}
}
// Copy PCCERT_CONTEXT from the unmanaged space to CERT_CONTEXT in managed space.
// certContext is ready to use now.
certContext =
pCertContext == IntPtr.Zero
? default
: Marshal.PtrToStructure<CERT_CONTEXT>(pCertContext);
}
finally
{
// The PCCERT_CONTEXT returned by MsiGetFileSignatureInformation must be
// freed with CertFreeCertificateContext.
if (pCertContext != IntPtr.Zero)
{
CertFreeCertificateContext(pCertContext);
}
}
The MsiGetFileSignatureInformation function takes the path to a file that has been digitally signed and returns the file's signer certificate and hash.
2/24/2022 2:22:44 PM - -75.172.62.230
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).