Python ECDSA,使用secp224k1曲线用私钥签名

2024-05-28 18:18:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我真的很难掌握这个第三方Python模块。 我试图在secp224k1下使用一个28字节的SHA-224摘要私钥对一个28字节的SHA-224摘要进行签名。在

我的尝试:

import ecdsa

private_key = int("b89ea7fcd22cc059c2673dc24ff40b978307464686560d0ad7561b83", 16).to_bytes(28, byteorder='big')
digest_msg = int("d8af940293347bc348df1896b0d93bf3952399702cef4fbf199d1cf4", 16).to_bytes(28, byteorder='big')

sk = SigningKey.generate(private_key, curve=ecdsa.secp224k1) 
sig = sk.sign_digest(digest_msg)

>> AttributeError: module 'ecdsa' has no attribute 'secp224k1'

无可救药的是,我甚至无法通过谷歌来摆脱这个错误。在


Tags: 模块tokey字节bytesmsgprivateecdsa
1条回答
网友
1楼 · 发布于 2024-05-28 18:18:10

我建议使用fastecdsa来完成这类任务。在

据我所知,ecdsa不支持secp224k1曲线。在

fastecdsa不支持从字符串导入密钥,但可以将其导出为pem格式,然后使用keys.import_key()导入。 检查一下here。在

from fastecdsa import keys, curve, ecdsa

#generating the private key over secp224k1 curve
private_key = keys.gen_private_key(curve=curve.secp224k1)

#get the public key from the corresponding private key
public_key = keys.get_public_key(private_key, curve=curve.secp224k1)

msg = "Sign this message with secp224k1"

r, s = ecdsa.sign(msg, private_key, curve.secp224k1)

print(ecdsa.verify((r, s), msg, public_key, curve.secp224k1))

输出:

^{pr2}$

相关问题 更多 >

    热门问题