我正在开发一种功能,以数字方式签署一些内容。我有一个私钥的有效证书。如何使用私钥和充气城堡进行数字签名?
我试过以下但是想要一些正确的方法来实现使用充气城堡:
X509Certificate2 signingCert =
CryptoHelper.FindCertificate("21A6107EC254457AAF3D4D6FD286FB79");
var rsaObj = (RSACryptoServiceProvider)signingCert.PrivateKey;
_privateKey = rsaObj.ExportParameters(true);
谢谢!
答案 0 :(得分:2)
根据您的代码,我根本不确切知道您需要什么,但X509命名空间/代码位于
bcgit/bc-csharp - X509并且有一个实用工具类可在System.Security.Cryptography
和BouncyCastle
之间进行转换
bcgit/bc-csharp - DotNetUtilities.cs
BouncyCastle得到了很多测试(和例子)。看看bcgit/bc-csharp - TestCertificateGen.cs也是如此。也许这有助于你。
编辑:一般来说它应该是这样的
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.X509;
// Your loaded certificate
X509Certificate cert = null;
// Your loaded RSA key
AsymmetricKeyParameter privateKey = null;
AsymmetricKeyParameter publicKey = cert.GetPublicKey();
ISigner signer = SignerUtilities.GetSigner(cert.SigAlgName);
// Init for signing, you pass in the private key
signer.Init(true, privateKey);
// Init for verification, you pass in the public key
signer.Init(false, publicKey);
问候