- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否有可能以某种方式保存或导出CX509PrivateKey
。我的想法是创建一个发送给 CA 的 CSR 以获得证书,然后......我必须以某种方式获得私钥但不知道如何,不幸的是在谷歌上找不到任何东西。
我的一段代码:
var objPrivateKey = new CX509PrivateKey();
objPrivateKey.Length = int.Parse(ConfigurationManager.AppSettings["objPrivateKeyLength"]);
objPrivateKey.KeySpec = X509KeySpec.XCN_AT_SIGNATURE;
objPrivateKey.KeyUsage = X509PrivateKeyUsageFlags.XCN_NCRYPT_ALLOW_ALL_USAGES;
objPrivateKey.MachineContext = false;
objPrivateKey.ExportPolicy = X509PrivateKeyExportFlags.XCN_NCRYPT_ALLOW_EXPORT_FLAG;
objPrivateKey.CspInformations = objCSPs;
objPrivateKey.Create();
最佳答案
其实我是这样解决这个任务的。 (这里有更多的代码,所以你可以理解我想做什么)。
到这里,所有的工作都完成了。
/*
using CERTADMINLib;
using CERTCLILib;
using CertSevAPI.Core.Models;
using CertSrvAPI.Core;
using CertSrvAPI.Core.Models;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Prng;
using Org.BouncyCastle.Pkcs;
using Org.BouncyCastle.Security;
using System;
*/
var caService = new CAService();
// Create a certificate request.
// The private key is here.
var caRequest = caService.CertRequest(subjectDN);
// Submit the certificate request and get the response.
var caResponse = caService.SendCertRequest(caRequest.Request);
// If certificated is not issued return null.
if (!caService.IsIssued(caResponse.Disposition))
{
return null;
}
// Download the P7B file from CA.
var p7b = new WebClient().DownloadData(
_appSettings.CERT_SRV + "/CertSrv/CertNew.p7b?ReqID=" + caResponse.CertRequest.GetRequestId() + "&Enc=bin");
try
{
var certCollection = new X509Certificate2Collection();
// Import the downloaded file.
certCollection.Import(p7b);
// Create a PKCS store.
var pfx = new Pkcs12Store();
// Insert root CA certificate into the PKCS store.
pfx.SetCertificateEntry("rootCert",
new X509CertificateEntry(DotNetUtilities.FromX509Certificate(certCollection[0])));
// Get the second certificate from the downloaded file.
// That one is the generated certificate for our request.
var certificateEntry = new X509CertificateEntry[1];
certificateEntry[0] = new X509CertificateEntry(DotNetUtilities.FromX509Certificate(certCollection[1]));
// Insert our certificate with the private key
// under the same alias so then we know that this private key
// is for our certificate.
pfx.SetKeyEntry("taxkey", new AsymmetricKeyEntry(caRequest.PrivateKey), certificateEntry);
var memoryStream = new MemoryStream();
// Stream PFX store using the desired password
// for our file.
pfx.Save(memoryStream, password.ToCharArray(), new SecureRandom());
var pfxBytes = memoryStream.GetBuffer();
pfxBytes = Pkcs12Utilities.ConvertToDefiniteLength(pfxBytes, password.ToCharArray());
// Here you can save the pfxBytes to a file, if you want.
// Actually I needed it to give as a response in MVC application.
return File(pfxBytes, System.Net.Mime.MediaTypeNames.Application.Octet, "NewCert.pfx");
}
catch (Exception ex)
{
// If there is an error remove private key from
// the memory.
caRequest.PrivateKey = null;
caRequest.Request = null;
ErrorSignal.FromCurrentContext().Raise(ex);
if (showError != null && showError.ToLower() == "true")
{
throw ex;
}
return null;
}
私钥在CARequest
中。
/*
using Org.BouncyCastle.Crypto;
*/
public class CARequestModel
{
public AsymmetricKeyParameter PrivateKey { get; set; }
public string Request { get; set; }
}
私钥保存在内存中,直到我们需要它保存到PFX文件的那一刻,它是在我们创建证书请求的那一刻生成的。所以这里是证书请求生成方法。
public CARequestModel CertRequest(string subjectDN)
{
var name = new X509Name(subjectDN);
var rsaKeyPairGenerator = new RsaKeyPairGenerator();
rsaKeyPairGenerator.Init(
new KeyGenerationParameters(new SecureRandom(
new CryptoApiRandomGenerator()), _appSettings.PRIVATE_KEY_LENGHT));
// Generate key pair.
var keyPair = rsaKeyPairGenerator.GenerateKeyPair();
// Get the private key.
var privateKey = keyPair.Private;
// Get the public key.
var publicKey = keyPair.Public;
// Set the key usage scope.
var keyUsage = new KeyUsage(KeyUsage.DigitalSignature);
var extensionsGenerator = new X509ExtensionsGenerator();
extensionsGenerator.AddExtension(X509Extensions.KeyUsage, true, keyUsage);
var attribute = new AttributeX509(
PkcsObjectIdentifiers.Pkcs9AtExtensionRequest, new DerSet(extensionsGenerator.Generate()));
// Create the certificate request
var csr = new Pkcs10CertificationRequest("SHA256withRSA", name, publicKey, new DerSet(attribute), privateKey);
// Get it as DER, because then I have to submit it to the MS CA server.
var csrBytes = csr.GetDerEncoded();
// Return the Request and private key
return
new CARequestModel
{
Request = Convert.ToBase64String(csrBytes),
PrivateKey = privateKey
};
}
关于c# - 导出或保存 CX509PrivateKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30039639/
NASM给出的错误(尽管我的操作系统正常)是“无效的有效地址”。 现在,我已经看到了许多关于如何使用LEA的示例,我认为我做对了,但是我的NASM不喜欢它。我尝试了lea cx, [cx+9]并成功了
我希望尽可能生成动态文本而不需要创建 webhook。我知道创建动态文本的唯一方法是根据参数创建不同的路由或通过 using inline system functions像文本实现中的 $sys.f
我需要知道如何查看实际对话以及与每个对话回合匹配的意图。 我在 上找不到完成对话/意图审查的方法Dialogflow CX 版。 (在 ES 版上非常简单)。 我需要访问他的功能(如果它在 CX 上实
我正在尝试填充 API 参数:https://cloud.google.com/dialogflow/cx/docs/quick/api . 我找不到任何关于如何在其文档中找到代理 ID 的引用:ht
我正在尝试填充 API 参数:https://cloud.google.com/dialogflow/cx/docs/quick/api . 我找不到任何关于如何在其文档中找到代理 ID 的引用:ht
我正在探索 Cx,这是一个基于 React ( http://cx.codaxy.com/ ) 的有趣的新框架,但我不知道如何访问组件内的 DOM 元素. 基本上,我有一个包含一些文本和一个按钮的简单
我是 WinRT 的新手。我正在将用 C++/CX 编写的 Windows UWP 应用程序转换为 C++/WinRT。我有一个 C++/CX ref 类,它基本上与 C# 中的 Microsoft.
每当我尝试在 DOSBox 下使用 MASM 6.15 时: mov al, [cx] 或者 mov al, [cx + bx] 或者 mov al, [cx + 4] 我收到错误消息:“只允许使用基
我想在 CDialog 的 OnInitDialog 期间获取 cx 和 cy。 我可以用下面的代码做到这一点: myDialog::OnInitDialog() { CRect rcWindow
这听起来像是一个愚蠢的问题,因为我知道这两种语言的实现是完全不同的。但是,我对细节有些不清楚。 我喜欢的 C++CLI 中一个非常好的特性是我可以拥有一个标准的 C# .NET 动态库并在 C++CL
我正在尝试使用 RPC DetectIntent 方法与 Dialogflow CX 代理交互,但出现错误“请切换到‘us-east1-dialogflow.googleapis.com’以访问位于‘
我有一个类: ref class Coord { public: property float X { float get() { return X; } vo
我是 C++/CX、IDL 和 WRL 的新手,遇到了一个问题我不确定是我的代码有错误还是设计的限制。 我有一个 IDL,它定义了一个 IInspectable 接口(interface)及其运行时类
我正在通过构建 Windows 应用商店应用来学习 C++/CX。对于我的 View 模型的基础,我使用标准的 BindableBase 类并向其添加了一个方便的 SetProperty 方法(我在我
我最近加入了一家新公司,并且是 python(他们首选的脚本语言)的新手,并且一直在使用 cx_oracle 创建一些 ETL 流程。到目前为止,我构建的脚本都是单线程作业,它们从 Oracle 源数
java.util.regex.Pattern 的 Javadoc 说 \cx 表示 x 对应的控制字符。所以我认为 Pattern.compile() 会拒绝 \c 后跟除 [@-_] 之外的任何字
我想使用 C++/CX 语法编写一个库并在其他项目中使用它。 如您所知,普通的旧数据结构不能有任何方法或运算符,因此我们不得不做一些事情,例如在另一个类中编写静态方法来提供行为。 我们也不能这样写代码
我正在尝试使用以下汇编代码将磁盘扇区加载到内存中,但正如我在终端中使用一些 int 0x10 时发现的那样,它不起作用的原因是它陷入了无限循环。我以为循环会自动为我递减 cx 寄存器。下面是代码,其中
我关注了this tutorial用于在 Mac 上安装 cx_oracle。经过一些调整,它成功了。我之前使用的是 Mavericks。然后我升级到 El Capitan。这就是灾难的来源。 它停止
我一直在学习x86汇编语言,PUSHA指令产生了一个问题。 据我所知,Pusha和PUSH AX, CX, DX, BX, original SP, BP, SI, DI一样。 我想知道的是为什么在
我是一名优秀的程序员,十分优秀!