简体   繁体   English

使用充气城堡和证书私钥的数字签名

[英]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.CryptographyBouncyCastle之间进行转换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.

相关问题 如何读取 Pem 证书和私钥文件并创建 Bouncy Castle X509Certificate 和 Bouncy Castle AsymmetricKeyParameter dotnet 核心? - How to Read a Pem Cert and Private Key Files and create Bouncy Castle X509Certificate and Bouncy Castle AsymmetricKeyParameter dotnet core? C#Bouncy Castle解码私钥 - C# Bouncy Castle decoding private key 使用 X509Certificate2 提示输入密码以使用私钥执行数字签名 - Performing a digital signature using X509Certificate2 prompt for a password to use private key 充气城堡的CMS签名X509证书 - CMS Signature X509 Certificate with Bouncy Castle 充气城堡 ECDSA 从私钥创建公钥 - Bouncy Castle ECDSA Create Public Key from Private Key 从Bouncy Castle C中的私钥获取公钥# - Get public key from private key in Bouncy Castle C# 通过X509Certificate加载时,私钥证书不支持数字签名 - Private key certificate does not support digital signature when loaded via X509Certificate Bouncy Castle解密c#中的私钥和加密文本 - Bouncy Castle Decryption in c# from private key and encrytedtext 将 ECC 私钥 PEM 读入 AsymmetricCipherKeyPair c# 充气城堡 - Read ECC private key PEM into AsymmetricCipherKeyPair c# bouncy castle 将Windows CryptoAPI私有密钥BLOB转换为有弹性的城堡RsaPrivateCrtKeyParameters - Convert Windows CryptoAPI PRIVATE KEY BLOB to bouncy castle RsaPrivateCrtKeyParameters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM