예제 #1
0
        public static byte[] GetCertificateProperty(
            SafeCertContextHandle certificateContext,
            NativeMethods.Crypt32.CertificateProperty property)
        {
            var pcbData = 0;

            if (!NativeMethods.Crypt32.CertGetCertificateContextProperty(
                    certificateContext,
                    property,
                    null,
                    ref pcbData)
                )
            {
                var code = (ErrorCode)Marshal.GetLastWin32Error();
                if (code != ErrorCode.MoreData)
                {
                    throw new CryptographicException((int)code);
                }
            }
            var pvData = new byte[pcbData];

            if (!NativeMethods.Crypt32.CertGetCertificateContextProperty(
                    certificateContext,
                    property,
                    pvData,
                    ref pcbData)
                )
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }
            return(pvData);
        }
예제 #2
0
 internal static unsafe T GetCertificateProperty <T>(
     SafeCertContextHandle certificateContext,
     NativeMethods.Crypt32.CertificateProperty property
     ) where T : struct
 {
     fixed(byte *numRef =
           GetCertificateProperty(certificateContext, property))
     {
         return((T)Marshal.PtrToStructure(new IntPtr(numRef), typeof(T)));
     }
 }
예제 #3
0
        internal static bool HasCertificateProperty(
            SafeCertContextHandle certificateContext,
            NativeMethods.Crypt32.CertificateProperty property)
        {
            var pcbData = 0;

            if (!NativeMethods.Crypt32.CertGetCertificateContextProperty(
                    certificateContext,
                    property,
                    null,
                    ref pcbData)
                )
            {
                return(Marshal.GetLastWin32Error() == (int)ErrorCode.MoreData);
            }
            return(true);
        }