簡體   English   中英

使用充氣城堡和證書私鑰的數字簽名

[英]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.CryptographyBouncyCastle之間進行轉換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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM