[英]Digital signature using bouncy castle and certificate private key
I am developing a feature to digital sign some content. 我正在开发一项功能,对一些内容进行数字签名。 I have valid certificate with a private key.
我有带私钥的有效证书。 How to digital sign using the private key and bouncy castle?
如何使用私钥和充气城堡进行数字签名?
I tried the following but want some right way to achieve the same using bouncy castle: 我尝试了以下操作,但希望通过弹力城堡实现正确的方法:
X509Certificate2 signingCert =
CryptoHelper.FindCertificate("21A6107EC254457AAF3D4D6FD286FB79");
var rsaObj = (RSACryptoServiceProvider)signingCert.PrivateKey;
_privateKey = rsaObj.ExportParameters(true);
Thanks! 谢谢!
I don´t know exactly what you need based on your code, but there X509 namespace/code is at bcgit/bc-csharp - X509 and there is an utility class for conversion between System.Security.Cryptography
and BouncyCastle
bcgit/bc-csharp - DotNetUtilities.cs 我不完全知道您根据代码需要什么,但是X509命名空间/代码位于bcgit / bc-csharp-X509,并且有一个实用程序类,用于在
System.Security.Cryptography
和BouncyCastle
之间进行转换bcgit / bc-csharp -DotNetUtilities.cs
BouncyCastle got lots of test (and examples). BouncyCastle得到了很多测试(和示例)。 Have a look at bcgit/bc-csharp - TestCertificateGen.cs too.
看看bcgit / bc-csharp-TestCertificateGen.cs 。 Maybe this helps you.
也许这对您有帮助。
EDIT: In general it should go something like this 编辑:一般来说,它应该像这样
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);
Greetings 问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.