当前位置: 首页>>代码示例>>C#>>正文


C# X509Certificate2Collection.Export方法代码示例

本文整理汇总了C#中System.Security.Cryptography.X509Certificates.X509Certificate2Collection.Export方法的典型用法代码示例。如果您正苦于以下问题:C# X509Certificate2Collection.Export方法的具体用法?C# X509Certificate2Collection.Export怎么用?C# X509Certificate2Collection.Export使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.X509Certificates.X509Certificate2Collection的用法示例。


在下文中一共展示了X509Certificate2Collection.Export方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CloneCertChain

        private void CloneCertChain(Uri url, string destination)
        {
            IProxyClientFactory factory = proxyClientControl.Client;

            if (factory == null)
            {
                factory = new IpProxyClientFactory();
            }

            ProxyClient client = factory.Create(new Logger());
            collection = new X509Certificate2Collection();

            using (IDataAdapter adapter = client.Connect(new IpProxyToken(null, url.Host, url.Port, IpProxyToken.IpClientType.Tcp, false),
                new Logger(), new Nodes.MetaDictionary(), new Nodes.MetaDictionary(), new PropertyBag(), new Security.CredentialsManagerService()))
            {
                DataAdapterToStream stm = new DataAdapterToStream(adapter);

                using (SslStream ssl = new SslStream(stm, false, VerifyCallback))
                {
                    ssl.AuthenticateAsClient(url.Host);
                }
            }

            if (collection.Count > 0)
            {
                File.WriteAllBytes(Path.Combine(destination, String.Format("certchain_{0}.pfx", url.Host)), collection.Export(X509ContentType.Pfx));
                int count = 1;

                foreach (X509Certificate2 cert in collection)
                {
                    string path = Path.Combine(destination, String.Format("cert_{0}_{1}.cer", url.Host, count++));

                    File.WriteAllText(path, CertificateUtils.ExportToPEM(cert) +
                        CertificateUtils.ExportToPEM((RSA)cert.PrivateKey, null));
                }
            }
        }
开发者ID:michyer,项目名称:canape,代码行数:37,代码来源:CloneCertChainForm.cs

示例2: Create

 /// <summary>
 /// Export the given certificate collection as an UNSIGNED bundle
 /// </summary>
 /// <param name="certs">Certificates to place in the bundle</param>
 /// <returns>p7b data</returns>
 public static byte[] Create(X509Certificate2Collection certs)
 {
     return certs.Export(X509ContentType.Pkcs7);
 }
开发者ID:DM-TOR,项目名称:nhin-d,代码行数:9,代码来源:AnchorBundle.cs

示例3: CreateSigned

        /// <summary>
        /// Export the given certificate collection as a SIGNED bundle 
        /// </summary>
        /// <param name="certs">Certificates to place in the bundle</param>
        /// <param name="signingCert">Signing certificate</param>
        /// <returns>p7s data</returns>
        public static byte[] CreateSigned(X509Certificate2Collection certs, X509Certificate2 signingCert)
        {
            if (signingCert == null || !signingCert.HasPrivateKey)
            {
                throw new ArgumentException("signingCert");
            }
            
            byte[] p7bData = certs.Export(X509ContentType.Pkcs7);

            SignedCms cms = new SignedCms(new ContentInfo(p7bData), false);
            CmsSigner signer = new CmsSigner(signingCert);
            signer.IncludeOption = X509IncludeOption.EndCertOnly;
            cms.ComputeSignature(signer, true);

            return cms.Encode();
        }
开发者ID:DM-TOR,项目名称:nhin-d,代码行数:22,代码来源:AnchorBundle.cs

示例4: ExportKeyFile

 /// <summary>
 /// Exports this store as a keyfile
 /// </summary>
 /// <param name="filePath">The path to which to export.</param>
 /// <param name="password">The password for the new keyfile</param>
 /// <param name="type">The <see cref="X509ContentType"/> for the new keyfile.</param>
 public void ExportKeyFile(string filePath, string password, X509ContentType type)
 {
     X509Certificate2Collection certs = new X509Certificate2Collection();
     certs.Add(this);
     byte[] blob = certs.Export(type, password);
     
     System.IO.File.WriteAllBytes(filePath, blob);
 }
开发者ID:DM-TOR,项目名称:nhin-d,代码行数:14,代码来源:CertificateStore.cs


注:本文中的System.Security.Cryptography.X509Certificates.X509Certificate2Collection.Export方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。