ECDSA签名使用OpenSSL而不使用ASN1编码的哈希值 [英] ECDSA sign using OpenSSL without ASN1 encoding the hash

查看:1104
本文介绍了ECDSA签名使用OpenSSL而不使用ASN1编码的哈希值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 dgst 命令使用OpenSSL执行ECDSA签名的操作如下:

Im doing ECDSA signatures using dgst command with OpenSSL as follows:

openssl dgst -sha256 -sign key.pem -out my_signature data_file

这很好。但是,我在这个答案中读到它首先SHA256散列data_file,

which works just fine. However I read in this SO answer that it first SHA256 hashes the data_file, and ASN.1 encodes the hash before signing it.

我想要创建SHA256数据哈希,并使ECDSA只签名原始这个哈希的字节。 (因为这是ECDSA签名,所以我不能像上面提到的答案中那样使用 rsautl 。)

I would like to create the SHA256 hash of the data and make ECDSA sign just the raw bytes of this hash. (As this is the ECDSA signature, I cannot use rsautl as in the mentioned SO answer.)

我使用OpenSSL实现这个目的?

How do I achieve this using OpenSSL?

推荐答案

可以使用 openssl pkeyutl

假设你想要哈希和哈希,并且它是一个替代 openssl rsautl
。使用openssl签署一个'data.txt'文件。首先,
需要哈希文件:

Suppose you want to hash and sign a 'data.txt' file with openssl. At first you need to hash the file:

openssl dgst -sha256 -binary -out data.sha256 data.txt

之后您可以签名:

openssl pkeyutl -sign -inkey private.pem -in data.sha256 -out data.sig

但是签名仍然是ASN.1格式。接收r和s值
签名使用 openssl asn1parse

However the signature is still in ASN.1 format. To receive r and s values of signature use openssl asn1parse:

openssl asn1parse -inform DER -in data.sig

这篇关于ECDSA签名使用OpenSSL而不使用ASN1编码的哈希值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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