.net pkcs#7/12 sign detached
public static string Sign(string myString)
{
X509Certificate2 cert = new X509Certificate2(@"xxxxx.pfx", "123456");
CmsSigner signer = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, cert);
signer.DigestAlgorithm = new Oid(Oids.Sha1);
ContentInfo content = new ContentInfo(new Oid(Oids.Pkcs7Data), Encoding.UTF8.GetBytes(myString));
SignedCms signedCms = new SignedCms(content, true);
signedCms.ComputeSignature(signer, false);
var asig = signedCms.Encode();
return Convert.ToBase64String(asig);
}
本文来自博客园,作者:gui.h,转载请注明原文链接:https://www.cnblogs.com/springhgui/p/16596765.html