我有一套问题:
2.这个问题主要是因为我没有1的密码器。-如果我有字节数组形式的公钥,如何在C#中验证签名?我在网上发现了这个,但它还是使用了一些电子邮件中的文字,我真的不知道发生了什么:
public static bool Verify(byte[] signature, string text)
{
X509Certificate2 certificate = new X509Certificate2(@"D:\My-CV.docx.p7s");
if (signature == null)
throw new ArgumentNullException("signature");
if (certificate == null)
throw new ArgumentNullException("certificate");
//hash the text
// Methode 3 for Hashing
System.Security.Cryptography.SHA1 hash3 = System.Security.Cryptography.SHA1.Create();
System.Text.UnicodeEncoding encoder = new System.Text.UnicodeEncoding();
byte[] combined = encoder.GetBytes(text);
byte[] hash3byte = hash3.ComputeHash(combined);
//Adding the text from the email, to a contentInfo
ContentInfo content = new ContentInfo(hash3byte);
// decode the signature
SignedCms verifyCms = new SignedCms(content, true);
verifyCms.Decode(signature);
// verify it
try
{
verifyCms.CheckSignature(new X509Certificate2Collection(certificate), false);
return true;
}
catch (CryptographicException)
{
return false;
}
} 有人能帮我吗?
发布于 2013-10-24 08:58:06
.p7s文件包含文档的签名。内容没有加密,但看起来像。
文档文件要大得多,因为它包含日期,.p7s签名。
若要检查签名,您需要签署文档的证书的公共部分。
您可以检查这两个帖子以检查签名:
最后一件事是从p7s文件加载签名数据。我做了些搜索,然后回到你身边。
https://stackoverflow.com/questions/19561181
复制相似问题