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

Decode_CERT_NAME_BLOB() public static method

Decodes a CERT_NAME_BLOB.
public static Decode_CERT_NAME_BLOB ( CERT_NAME_BLOB blob ) : string
blob CERT_NAME_BLOB
return string
        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);
                }
            }
        }

Usage Example

コード例 #1
0
ファイル: X509CRL.cs プロジェクト: benvert/pfe
        private void Initialize(byte[] crl)
        {
            m_bufferSize = crl.Length;
            m_pBuffer    = Marshal.AllocHGlobal(m_bufferSize);
            Marshal.Copy(crl, 0, m_pBuffer, m_bufferSize);
            SaveUnmanagedPointer(m_pBuffer);

            m_signedCrl = Win32.Decode_CERT_SIGNED_CONTENT_INFO(m_pBuffer, crl.Length);
            Win32.CRL_INFO info = Win32.Decode_CERT_INFO(m_signedCrl.ToBeSigned.pbData, m_signedCrl.ToBeSigned.cbData);

            Issuer         = Win32.Decode_CERT_NAME_BLOB(info.Issuer);
            UpdateTime     = Win32.Decode_FILETIME(info.ThisUpdate);
            NextUpdateTime = Win32.Decode_FILETIME(info.NextUpdate);
        }