如何使用 openssl 验证文件和 p7s 分离签名? [英] How to verify a file and a p7s detached signature with openssl?

查看:24
本文介绍了如何使用 openssl 验证文件和 p7s 分离签名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以验证带有 p7s 分离签名的文件?我正在尝试使用 Openssl 执行此操作,但我收到了有关 openssl 和 unknown option -verify

Would be possible to validate a file with p7s detached signature? I'm trying to do that using Openssl, but I got a default message about openssl and unknown option -verify

这是我的命令:

openssl pkcs7 -inform DER -verify -noverify -in file.docx.p7s -out file.docx

是否可以使用 openssl 进行文件验证和 p7s 签名?

is this possible to do a file verification and p7s signature using openssl?

--编辑...

只是为了让你知道.我得到了一个带有 pdf 文件的 p7s 文件.我想知道如何验证.

Just to let you know. I got an p7s file with an pdf file. I'd like to know how to validate that.

推荐答案

最后,我对p7s文件有了一点了解.这对于保护电子邮件消息很常见,但是,我可以使用 p7s 文件,其中包含带有证书的 PKCS#7 分离签名,以确保文件的准确性.

Finally, I understand a litte bit about p7s file. This is pretty common to securing e-mail messages, but, I can use p7s files, that contains an PKCS#7 detached signatures with an certificate, to ensure the veracity of a file.

所以,我将我的解释分开,部分内容是为了便于解释我在这里所做的事情.如有错误请指正!

So, I sepparate my explanation, in parts to get easy to explain what I'm doing here. Please, correct me if there's something wrong!

首先,初始配置:

  1. 创建私钥和证书

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365

二、创建p7s文件

  1. 运行以下命令以使用私钥、证书对 pdf 文件进行签名,并生成一个 p7s 文件,其中包含文件的签名哈希和证书

openssl smime -sign -in test.pdf -inkey key.pem -outform DER -binary -signer cert.pem -out test.pdf.p7s

最后,验证 p7s 文件

  1. 现在,我必须从 p7s 文件中提取 pkcs7 签名

openssl pkcs7 -inform der -in test.pdf.p7s -out test.pdf.pkcs7

  1. 之后,我从 pkcs7 文件中提取了证书

openssl pkcs7 -print_certs -in test.pdf.pkcs7 -out test.pdf.pkcs7.cert

  1. 然后,一起验证pkcs7、证书和文件.只是为了验证该文件是否属于该证书

openssl smime -verify -binary -inform PEM -in test.pdf.pkcs7 -content test.pdf -certfile test.pdf.pkcs7.cert -nointern -noverify > /dev/null

这篇关于如何使用 openssl 验证文件和 p7s 分离签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆