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?

3

Yes:

import ecdsa
print(ecdsa.SigningKey.generate(curve=ecdsa.SECP256k1).to_string())
  • 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 :( – Sergey Potekhin Nov 10 '16 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 Nov 10 '16 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? – Sergey Potekhin Nov 10 '16 at 20:45
  • *a key which looks the same – Sergey Potekhin Nov 10 '16 at 21:00
  • 1
    Use binascii.hexlify(key.to_string()).decode('ascii').upper() – Nick ODell Nov 10 '16 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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