VCSJones.FiddlerCert.CtVerifier.DecodeSubjectPublicKeyInfo C# (CSharp) Method

DecodeSubjectPublicKeyInfo() private static method

private static DecodeSubjectPublicKeyInfo ( byte publicKey ) : CtPublicKey
publicKey byte
return CtPublicKey
        private static CtPublicKey DecodeSubjectPublicKeyInfo(byte[] publicKey)
        {
            const EncodingType encodingType = EncodingType.PKCS_7_ASN_ENCODING | EncodingType.X509_ASN_ENCODING;
            var handle = default(GCHandle);
            try
            {
                handle = GCHandle.Alloc(publicKey, GCHandleType.Pinned);
                LocalBufferSafeHandle buffer;
                var size = 0u;
                if (Crypto32.CryptDecodeObjectEx(encodingType, SUBJECT_PUBLIC_KEY_INFO, handle.AddrOfPinnedObject(), (uint)publicKey.Length, CryptDecodeFlags.CRYPT_DECODE_ALLOC_FLAG, IntPtr.Zero, out buffer, ref size))
                {
                    using (buffer)
                    {
                        //don't free the buffer until the structure's been fully read.
                        var structure = (CERT_PUBLIC_KEY_INFO)Marshal.PtrToStructure(buffer.DangerousGetHandle(), typeof(CERT_PUBLIC_KEY_INFO));
                        return FromWin32Structure(structure);
                    }
                }
                else
                {
                    return null;
                }
            }
            finally
            {
                if (handle.IsAllocated)
                {
                    handle.Free();
                }
            }
        }