Opc.Ua.Win32.CertNameToStrW C# (CSharp) Method

CertNameToStrW() private method

private CertNameToStrW ( int dwCertEncodingType, IntPtr pName, int dwStrType, IntPtr psz, int csz ) : int
dwCertEncodingType int
pName System.IntPtr
dwStrType int
psz System.IntPtr
csz int
return int
        public static extern int CertNameToStrW(
            int dwCertEncodingType,
            IntPtr pName,
            int dwStrType,
            IntPtr psz,
            int csz);

Usage Example

コード例 #1
0
ファイル: Win32.cs プロジェクト: martycav/UANodeSet
        /// <summary>
        /// Decodes a CERT_NAME_BLOB.
        /// </summary>
        public static string Decode_CERT_NAME_BLOB(CERT_NAME_BLOB blob)
        {
            int    dwChars = 0;
            IntPtr pName   = IntPtr.Zero;
            IntPtr pBlob   = IntPtr.Zero;

            try
            {
                pBlob = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Win32.CERT_NAME_BLOB)));
                Marshal.StructureToPtr(blob, pBlob, false);

                int bResult = Win32.CertNameToStrW(
                    Win32.PKCS_7_ASN_ENCODING | Win32.X509_ASN_ENCODING,
                    pBlob,
                    Win32.CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG,
                    IntPtr.Zero,
                    dwChars);

                if (bResult == 0)
                {
                    throw GetLastError(StatusCodes.BadDecodingError, "Could not get size of CERT_X500_NAME_STR.");
                }

                dwChars = bResult;
                pName   = Marshal.AllocHGlobal((dwChars + 1) * 2);

                bResult = Win32.CertNameToStrW(
                    Win32.PKCS_7_ASN_ENCODING | Win32.X509_ASN_ENCODING,
                    pBlob,
                    Win32.CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG,
                    pName,
                    dwChars);

                if (bResult == 0)
                {
                    throw GetLastError(StatusCodes.BadDecodingError, "Could not decode CERT_X500_NAME_STR.");
                }

                return(Marshal.PtrToStringUni(pName));
            }
            finally
            {
                if (pBlob != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pBlob);
                }

                if (pName != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pName);
                }
            }
        }