[英]Verify electronic signature in .NET
我有一系列問題:
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;
}
}
有人可以幫我弄這個嗎?
.p7s文件包含文檔的簽名。 內容未加密,但是看起來像。
文檔文件要大得多,因為它包含日期,.p7s簽名。
要檢查簽名,您需要用於簽署文檔的證書的公共部分。
您可以檢查這兩個帖子以檢查簽名:
最后一件事是從p7s文件加載簽名數據。 我進行了搜索,然后再找您。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.