2015-09-25 54 views
0

,我发展到数字标牌功能的一些内容。我有一个私钥的有效证书。如何使用私钥和充气城堡进行数字签名?数字签名使用充气城堡和证书私钥

我尝试以下,但需要一些正确的方式来达到同样的使用充气城堡:

X509Certificate2 signingCert = 
    CryptoHelper.FindCertificate("21A6107EC254457AAF3D4D6FD286FB79"); 

var rsaObj = (RSACryptoServiceProvider)signingCert.PrivateKey; 
_privateKey = rsaObj.ExportParameters(true); 

谢谢!

+0

你的问题甚至不包含任何签名生成。而且SO不是为您编写代码的服务。 –

+0

@stackers是的,那是我......任何问题或意见? –

回答

2

我不知道你需要什么根据你的代码,但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); 

问候

+0

谢谢。基本上我有证书,并有证书中的私钥。我想用弹性城堡对字符串进行数字签名。 –