1

I am currently experimenting with elliptic curves and using python for simplicity.

I have an instance of this class (NaCl/PrivateKey) which is properly instantiated.

However looking at it's public class variables, I can only seem to query the size.

Is it my misunderstanding, is there a public variable I can query to fetch the underlying private key data (again I'm just playing and learning, not for production).

I've been able to print the privateKey instance and it prints a direct byte array like this: \xa6_\xe5\xa3\xc3\xdd\x96\x04C\x03%\x0f\xe7)y\x92\n\xf7#\xee\xcdo\xff\xaf%\xedZ\xd4\x0e\xecr\xb4

I can then prefix a b in a Python repl with a .toHex call to get:

a65fe5a3c3dd96044303250fe72979920af723eecd6fffaf25ed5ad40eec72b4

Is there any Python ninja that can guide me on a more direct access from the instance directly?

Best I can do is print(binascii.hexlify(privateKey.__bytes__())) - but that doesn't seem like an appropriate way to do it, accessing __bytes__ directly

Woodstock
  • 22,184
  • 15
  • 80
  • 118
  • To export raw, another way is to use base64. I used it to share files: [my repo](https://github.com/PabloLION/symmetric-secrete-share) – Pablo LION Feb 03 '22 at 05:39

1 Answers1

2

print(bytes(privateKey).hex()) is the answer. The __bytes__ method is a magic method that is called when an object is converted to bytes. bytes objects have a method hex to convert them.

blues
  • 4,547
  • 3
  • 23
  • 39
  • Thank you! `The __bytes__ method is a magic method` like a system method? i.e. shouldn't be directly called – Woodstock Jul 24 '19 at 13:43
  • Yes, it shouldn't be directly called. See [this question and answer](https://stackoverflow.com/questions/1090620/special-magic-methods-in-python) for more. – blues Jul 24 '19 at 13:45