public static CRL_INFO Decode_CERT_INFO(IntPtr pEncoded, int iEncodedSize)
{
IntPtr pData2 = IntPtr.Zero;
int dwDataSize2 = 0;
try
{
// calculate amount of memory required.
int bResult = Win32.CryptDecodeObjectEx(
Win32.X509_ASN_ENCODING | Win32.PKCS_7_ASN_ENCODING,
(IntPtr)Win32.X509_CERT_CRL_TO_BE_SIGNED,
pEncoded,
iEncodedSize,
Win32.CRYPT_DECODE_NOCOPY_FLAG,
IntPtr.Zero,
pData2,
ref dwDataSize2);
if (bResult == 0)
{
throw GetLastError(StatusCodes.BadDecodingError, "Could not get size for CRL_INFO.");
}
// allocate memory.
pData2 = Marshal.AllocHGlobal(dwDataSize2);
// decode blob.
bResult = Win32.CryptDecodeObjectEx(
Win32.X509_ASN_ENCODING | Win32.PKCS_7_ASN_ENCODING,
(IntPtr)Win32.X509_CERT_CRL_TO_BE_SIGNED,
pEncoded,
iEncodedSize,
Win32.CRYPT_DECODE_NOCOPY_FLAG,
IntPtr.Zero,
pData2,
ref dwDataSize2);
if (bResult == 0)
{
throw GetLastError(StatusCodes.BadDecodingError, "Could not decode CRL_INFO.");
}
return (Win32.CRL_INFO)Marshal.PtrToStructure(pData2, typeof(Win32.CRL_INFO));
}
finally
{
if (pData2 != IntPtr.Zero)
{
Marshal.FreeHGlobal(pData2);
}
}
}