![](/img/trans.png)
[英]How to Read a Pem Cert and Private Key Files and create Bouncy Castle X509Certificate and Bouncy Castle AsymmetricKeyParameter dotnet core?
[英]Digital signature using bouncy castle and certificate private key
我正在開發一項功能,對一些內容進行數字簽名。 我有帶私鑰的有效證書。 如何使用私鑰和充氣城堡進行數字簽名?
我嘗試了以下操作,但希望通過彈力城堡實現正確的方法:
X509Certificate2 signingCert =
CryptoHelper.FindCertificate("21A6107EC254457AAF3D4D6FD286FB79");
var rsaObj = (RSACryptoServiceProvider)signingCert.PrivateKey;
_privateKey = rsaObj.ExportParameters(true);
謝謝!
我不完全知道您根據代碼需要什么,但是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);
問候
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.