I'm really having a hard time getting to get to grips with this 3rd party Python module. I'm trying to sign a 28-byte SHA-224 digest using a 28-byte SHA-224 digest private key under secp224k1.
My attempt:
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'
Hopelessly, I can't even google my way out of this error.
答案 0 :(得分:1)
我建议使用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))
输出:
True