因此,我需要使用ECC spec256k1从相应的256位数字中获取公共密钥。
所以,可以说我从任何密码短语中使用sha256获得了私钥,如下所示:
>>> import hashlib
>>> private_key = hashlib.sha3_256(b"Led Zeppelin - No Quarter").hexdigest()
>>> private_key
'c0b279f18074de51d075b152c8ce78b7bddb284e8cfde19896162abec0a0acce'
如何从该私钥中获取公钥?我需要将公共密钥打印为字符串。
椭圆曲线签名算法(source):
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import ec
private_key = ec.generate_private_key(
... ec.SECP384R1(), default_backend()
... )
data = b"this is some data I'd like to sign"
signature = private_key.sign(
... data,
... ec.ECDSA(hashes.SHA256())
... )
from cryptography.hazmat.primitives.asymmetric import utils
chosen_hash = hashes.SHA256()
hasher = hashes.Hash(chosen_hash, default_backend())
hasher.update(b"data & ")
hasher.update(b"more data")
digest = hasher.finalize()
sig = private_key.sign(
... digest,
... ec.ECDSA(utils.Prehashed(chosen_hash))
... )
这是您的公钥:
public_key = private_key.public_key()
public_key.verify(signature, data, ec.ECDSA(hashes.SHA256()))
阅读更多here。