我创建了一个pkcs7块,可以自己验证,但是结果和我使用OpenSSL的伙伴不一样。我创建的p7块无法被我的伙伴验证。
我们仔细检查代码,只找到c#中找不到对应项的代码,
OPENSSL:
signInfo->digest_enc_alg->algorithm=OBJ_nid2obj(NID_rsaEncryption);
这是.net 4.0中我们C#的代码,大家知道如何使用吗RSA加密 in p7?
public static string Sign(byte[] data, X509Certificate2 certificate)
{
if (data == null)
throw new ArgumentNullException("data");
if (certificate == null)
throw new ArgumentNullException("certificate");
//1 setup the data to sign
Oid digestOid = new Oid("1.2.840.113549.1.7.2");//pkcs7 signed
ContentInfo content = new ContentInfo(digestOid, data);
try
{
//2,SignerCms
SignedCms signedCms = new SignedCms(content, true); //detached = true
//3. CmsSigner
CmsSigner signer = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, certificate);
signer.DigestAlgorithm = new Oid("1.3.14.3.2.26");//sha1
//4.create signature
signedCms.ComputeSignature(signer);
//5,to Base64
byte[] signEnv = signedCms.Encode();
return Convert.ToBase64String(signEnv);
}catch (Exception e)
{
Console.WriteLine(e);
}
return null;
}
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)