3

This question may seem simple for those who know the library. How do I get the actual value of the private and public keys? I have

private_key = SigningKey.generate(SECP256k1)
public_key = private_key.get_verifying_key()
print("private_key:")
print(private_key)
print("public_key:")
print(public_key)

and it prints

generate_keys() private_key: <ecdsa.keys.SigningKey object at 0x7fd0a4ef56a0> public_key: VerifyingKey.from_string(b'\x029q\xfd\xe9\x1dL\xc0\xab\xb1\xd2GG\xef8\xcb\x89\xce\xbb\xa8\x10*\xfa\xda\x0c\x92\x12\xa5\xa0\x81\xef\x07\x9e', SECP256k1, sha1) (<ecdsa.keys.SigningKey object at 0x7fd0a4ef56a0>, VerifyingKey.from_string(b'\x029q\xfd\xe9\x1dL\xc0\xab\xb1\xd2GG\xef8\xcb\x89\xce\xbb\xa8\x10*\xfa\xda\x0c\x92\x12\xa5\xa0\x81\xef\x07\x9e', SECP256k1, sha1))

I need the private_key and public_key real values. How do I get them?

1 Answer 1

4

You have generated the private and public keys correctly. You now have class instances. These instances are not necessarily printing the way you expect - I think that is your only issue.

If you want to see PEM format, you should do this:

private_key = SigningKey.generate(SECP256k1)
public_key = private_key.get_verifying_key()
print("private_key:")
print(private_key.to_pem())
print("public_key:")
print(public_key.to_pem())

For DER format, use to_der(). For raw bytes, use to_string().

If you are communicating a key to someone, to a wallet, to openssl, etc, you probably want PEM format.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.