首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用.NET验证电子签名

用.NET验证电子签名
EN

Stack Overflow用户
提问于 2013-10-24 08:48:10
回答 1查看 2.8K关注 0票数 0

我有一套问题:

  1. .p7s文件包含什么?我读到它通常是发送到电子邮件的加密消息,但在我的例子中,我在我的硬盘上有一个文件和一个.p7s文件。该文件比.p7s大得多,因此我想知道其中包含了什么(当然,以后如何使用它)。

2.这个问题主要是因为我没有1的密码器。-如果我有字节数组形式的公钥,如何在C#中验证签名?我在网上发现了这个,但它还是使用了一些电子邮件中的文字,我真的不知道发生了什么:

代码语言:javascript
复制
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;
            }
        } 

有人能帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2013-10-24 08:58:06

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

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

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

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19561181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档