2

Pretty same question was asked here, but maybe there is a way to generate keys using ecdsa module in just a few lines of code?

1 Answer 1

3

Yes:

import ecdsa
print(ecdsa.SigningKey.generate(curve=ecdsa.SECP256k1).to_string())
5
  • Thanks for answer! So, when I'm runnnig your code, I'm getting something like b'\xe9+\xf7\x97A\...... How can I convert it to a usual string? str() and .decode('utf-8') don't work :( Commented Nov 10, 2016 at 18:44
  • 1
    It's a bytes type. Interpreting it as ascii or as UTF-8 doesn't make any sense. Are you trying to convert to hex, or are you trying to print raw bytes to the terminal?
    – Nick ODell
    Commented Nov 10, 2016 at 18:51
  • Well, I mean that usually ECDSA private key looks like 18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725 according to this. So, how can I get an address which looks the same? Commented Nov 10, 2016 at 20:45
  • *a key which looks the same Commented Nov 10, 2016 at 21:00
  • 1
    Use binascii.hexlify(key.to_string()).decode('ascii').upper()
    – Nick ODell
    Commented Nov 10, 2016 at 22:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.