pycoin学习记录(1) ecdsa

from pycoin.ecdsa import public_pair_for_secret_exponent, generator_secp256k1, sign, verify

secret_exponent = 0x12345678
public_point = public_pair_for_secret_exponent(generator_secp256k1, secret_exponent)
print(public_point)
#(34813357333787095655854570013678492386437171793647468034632590672613466129603, 113175443345180820036993277072503093223432189984870333624366591240075159642741)

v = 0xaaaa2222dddd
signature = sign(generator_secp256k1, secret_exponent, v)
print(signature)
#(69801354415124429214169587882252271265498691554829156653789494051499139228734, 82755552345731319769645884235352624948453952392086876082355454932758778544609)

r = verify(generator_secp256k1, public_point, v, signature)
print(r)
#True

signature = signature[0],signature[1]+1
r = verify(generator_secp256k1, public_point, v, signature)
print(r)
#False

首先根据预先设置的私钥,即此处的0x12345678,生成对应的公钥public_point,即椭圆曲线上的一对点。

对于任意消息v,用私钥对其签名,得到签名值。

此时可以将公钥public_point,消息v,签名signature发布出去。

当第三方得到上述三个值时,便可以验证签名是否正确了。


你可能感兴趣的:(杂项)