Python ECDSA,用曲线secp224k1用私钥签名
Python ECDSA, sign with private key with curve secp224k1
我真的很难掌握这个第 3 方 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'
无奈,我什至google无法摆脱这个错误。
我建议使用 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
我真的很难掌握这个第 3 方 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'
无奈,我什至google无法摆脱这个错误。
我建议使用 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