當前位置: 首頁>>代碼示例>>C#>>正文


C# X509Extension.Sum方法代碼示例

本文整理匯總了C#中System.Security.Cryptography.X509Certificates.X509Extension.Sum方法的典型用法代碼示例。如果您正苦於以下問題:C# X509Extension.Sum方法的具體用法?C# X509Extension.Sum怎麽用?C# X509Extension.Sum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Security.Cryptography.X509Certificates.X509Extension的用法示例。


在下文中一共展示了X509Extension.Sum方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: MarshalExtensions

        /// <summary>
        /// Marshal array of extensions into one big buffer
        /// </summary>
        /// <param name="extensions">Array of extensions</param>
        /// <returns>An allocated buffer (from Marshal.AllocHGlobal) containing the data</returns>
        private IntPtr MarshalExtensions(X509Extension[] extensions)
        {
            int stringSize = extensions.Sum(x => Encoding.ASCII.GetByteCount(x.Oid.Value) + 1);
            int dataSize = extensions.Sum(x => x.RawData.Length);
            int structSize = Marshal.SizeOf(typeof(CryptoApiMethods.CERT_EXTENSION));

            IntPtr ret = IntPtr.Zero;
            IntPtr currStructPtr = IntPtr.Zero;
            IntPtr currDataPtr = IntPtr.Zero;
            IntPtr currStringPtr = IntPtr.Zero;

            ret = Marshal.AllocHGlobal((extensions.Length * structSize) + dataSize + stringSize);

            currStructPtr = ret;
            currDataPtr = ret + (extensions.Length * structSize);
            currStringPtr = currDataPtr + dataSize;

            foreach (var x in extensions)
            {
                byte[] oidString = Encoding.ASCII.GetBytes(x.Oid.Value + "\0");
                var certExt = new CryptoApiMethods.CERT_EXTENSION();
                certExt.pszObjId = currStringPtr;
                certExt.Value = new CryptoApiMethods.CRYPTOAPI_BLOB();
                certExt.Value.pbData = currDataPtr;
                certExt.Value.cbData = (uint)x.RawData.Length;
                certExt.fCritical = x.Critical;

                Marshal.StructureToPtr(certExt, currStructPtr, false);
                Marshal.Copy(oidString, 0, currStringPtr, oidString.Length);
                Marshal.Copy(x.RawData, 0, currDataPtr, x.RawData.Length);

                currStructPtr += structSize;
                currStringPtr += oidString.Length;
                currDataPtr += x.RawData.Length;
            }

            return ret;
        }
開發者ID:michyer,項目名稱:canape,代碼行數:43,代碼來源:NativeCertificateBuilder.cs


注:本文中的System.Security.Cryptography.X509Certificates.X509Extension.Sum方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。