Ejemplo n.º 1
0
        void m_initialize(Oid oid, Int32 majorVersion, Int32 minorVersion)
        {
            Oid = _eoid;
            Asn1Utils.EncodeObjectIdentifier(oid);
            Wincrypt.CERT_TEMPLATE_EXT pvStructInfo = new Wincrypt.CERT_TEMPLATE_EXT {
                pszObjId       = oid.Value,
                dwMajorVersion = (UInt32)majorVersion,
                dwMinorVersion = (UInt32)minorVersion,
                fMinorVersion  = true
            };
            UInt32 pcbEncoded = 0;

            if (Crypt32.CryptEncodeObject(1, "1.3.6.1.4.1.311.21.7", ref pvStructInfo, null, ref pcbEncoded))
            {
                RawData = new Byte[pcbEncoded];
                Crypt32.CryptEncodeObject(1, "1.3.6.1.4.1.311.21.7", ref pvStructInfo, RawData, ref pcbEncoded);
                TemplateOid  = new Oid(pvStructInfo.pszObjId);
                MajorVersion = majorVersion;
                MinorVersion = minorVersion;
            }
            else
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
Ejemplo n.º 2
0
 internal static extern Boolean CryptEncodeObject(
     [In]                    UInt32 dwCertEncodingType,
     [In]                    String lpszStructType,
     [In] ref Wincrypt.CERT_TEMPLATE_EXT pvStructInfo,
     [Out]                   Byte[] pbEncoded,
     [In, Out] ref UInt32 pcbEncoded
     );
Ejemplo n.º 3
0
        void m_decode(Byte[] rawData)
        {
            UInt32 pcbStructInfo = 0;

            if (Crypt32.CryptDecodeObject(1, "1.3.6.1.4.1.311.21.7", rawData, (UInt32)rawData.Length, 0, IntPtr.Zero, ref pcbStructInfo))
            {
                IntPtr pbStructInfo = Marshal.AllocHGlobal((Int32)pcbStructInfo);
                Crypt32.CryptDecodeObject(1, "1.3.6.1.4.1.311.21.7", rawData, (UInt32)rawData.Length, 0, pbStructInfo, ref pcbStructInfo);
                Wincrypt.CERT_TEMPLATE_EXT structure = (Wincrypt.CERT_TEMPLATE_EXT)Marshal.PtrToStructure(pbStructInfo, typeof(Wincrypt.CERT_TEMPLATE_EXT));
                Marshal.FreeHGlobal(pbStructInfo);
                TemplateOid  = new Oid(structure.pszObjId);
                MajorVersion = (Int32)structure.dwMajorVersion;
                MinorVersion = (Int32)structure.dwMinorVersion;
            }
            else
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }