示例#1
0
        internal static unsafe string X500DistinguishedNameDecode(byte[] encodedDistinguishedName, OpenSslX09NameFormatFlags nativeFlags)
        {
            using (SafeX509NameHandle x509Name = Interop.libcrypto.OpenSslD2I(Interop.libcrypto.d2i_X509_NAME, encodedDistinguishedName))
            {
                Interop.libcrypto.CheckValidOpenSslHandle(x509Name);

                using (SafeBioHandle bioHandle = Interop.libcrypto.BIO_new(Interop.libcrypto.BIO_s_mem()))
                {
                    Interop.libcrypto.CheckValidOpenSslHandle(bioHandle);

                    int written = Interop.libcrypto.X509_NAME_print_ex(
                        bioHandle,
                        x509Name,
                        0,
                        new UIntPtr((uint)nativeFlags));

                    // X509_NAME_print_ex returns how many bytes were written into the buffer.
                    // BIO_gets wants to ensure that the response is NULL-terminated.
                    // So add one to leave space for the NULL.
                    StringBuilder builder = new StringBuilder(written + 1);
                    int read = Interop.libcrypto.BIO_gets(bioHandle, builder, builder.Capacity);

                    if (read < 0)
                    {
                        throw Interop.libcrypto.CreateOpenSslCryptographicException();
                    }

                    return builder.ToString();
                }
            }
        }
示例#2
0
        public string X500DistinguishedNameDecode(byte[] encodedDistinguishedName, X500DistinguishedNameFlags flags)
        {
            OpenSslX09NameFormatFlags nativeFlags = ConvertFormatFlags(flags);

            return(X500DistinguishedNameDecode(encodedDistinguishedName, nativeFlags));
        }