0

我有一组问题:

  1. .p7s 文件包含什么?我读到它通常是发送到电子邮件的加密消息,但就我而言,我的硬盘上有一个文件和一个 .p7s 文件。该文件比 .p7s 大得多,所以我想知道里面有什么(当然还有以后如何使用它)。

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;
            }
        } 

有人可以帮我弄这个吗?

4

1 回答 1

0

.p7s 文件包含您文档的签名。内容未加密,但看起来像。

文档文件要大得多,因为它包含日期、.p7s 签名。

要检查签名,您需要用于签署文档的证书的公共部分。

您可以检查这两个帖子来检查签名:

最后一件事是从 p7s 文件加载签名数据。我做了一些搜索,然后回到你身边。

于 2013-10-24T08:58:06.847 回答