如何仅使用带有OpenSSL的公共证书来验证文件签名?

时间:2020-02-24 19:49:49

标签: powershell cmd openssl

我必须验证使用私钥签名的文件(signedFile.txt)中的签名。如果我没记错的话,我只能访问从私钥生成的公共证书(.cer)。我使用的是poweshell,但为简化起见,我使用cmd命令和openssl发布了该证书。

我拥有的证书: certificate

Usig论文发布为指南x509 Certificate Manual Signature VerificationRSA sign and verify using Openssl : Behind the scene

使用cmd将.cer文件传递给.pem

openssl x509  -inform DER -outform PEM -in myCert.cer -pubkey -out myCertPem.pem

之后,我使用下一条命令从证书中获取了公钥:

openssl x509 -in myCertPem.pem -noout -pubkey > myPubKey.pem

我知道了

public key

使用此post我从证书中引出了签名算法

openssl x509 -in certPEMSAT.pem -text -noout -certopt ca_default -certopt no_validity -certopt no_serial -certopt no_subject -certopt no_extensions -certopt no_signame > sign.txt.sha256

Signature Algorithm

编辑1

使用powershell,我能够清理并将其转储为二进制文件

$sign = get-content sign.txt.sha256 | select-string -Pattern 'Signature 
Algorithm' -NotMatch | Out-File newSignature.txt
$sign = (get-content newSignature.txt) -join ' ' 
$sign = $sign -replace '(^\s+|\s+$)','' -replace '\s+',' '
Set-Content signBytes.bin $sign | Format-Hex

Signature binary

最后,只需要使用以下命令即可:

openssl dgst -sha256 -verify myPubKey.pem -signature signBytes.bin signedFile.txt

我知道在验证according this page之前,我必须将十六进制签名转换为二进制签名,但这就是我遇到的问题。

我仍然无法通过验证

0 个答案:

没有答案
相关问题