8

I can't find any way to get the unencrypted private key from an encrypted private key from the tezos client.

I have found a way using tezbox. You import a private key into tezbox and then show the private key. The key that it shows you is unencrypted. I am unable to import an encrypted private key into tezbox that has a 'blank' password so this method is not available to me.

I have been told I can use eztz using:

eztz.crypto.extractEncryptedKeys('edesk','password')`

And I have been told I can use pytezos using:

Key(key='edesk...', passphrase='123456').secret_key()

I can't figure out how to get the above options to work, though. I have tried the eztz node.js method, but I would appreciate an example of how to do this.

2
  • 2
    You need to import eztz lib first and then use this: eztz.crypto.extractEncryptedKeys(encryptedPrivateKey, password) It will return a full set of extracted keys. – Rodrigo Quelhas Feb 10 '19 at 16:31
  • Btw, that function is used on client side, will not work if you are using it on backend as it needs the window obj. You need to change it to work on backend. – Rodrigo Quelhas Feb 10 '19 at 16:55
5

With pytezos

import pytezos
print(pytezos.Key('edesk...', passphrase='yourpassword').secret_key())

UPD

>>> from pytezos import Key
>>> key = Key.generate()
>>> key.public_key_hash()
'tz1hQbcSWjcWLdcRjMDqpJVuTaaj9m2wMtwk'
>>> esk = key.secret_key(passphrase='12345'.encode())
>>> esk
'edesk1UrFQK6xJM6SYdLxMQbyKaaYQmzYVvQRpJXUmxj3apZ1ufRu4aHSTqWrJiqcHywSbnF146wkNcpUAW7Qy6H'
>>> Key.from_encoded_key(esk, passphrase='12345'.encode()).secret_key()
'edsk2juUM8ZMUkaCKHWVnzWhp9DxrK93YK1rQjYk3pTEq2ThXpBxkX'

According to the developer: "Passing password as bytes is not convenient indeed, plain string support will be added to mitigate this."

5
  • im getting this error : ``` File "/Users/user/Desktop/privkeyconvert/pytezos.py", line 54 def __init__(self, key: str, passphrase: str = None, email: str = None): ^ SyntaxError: invalid syntax``` – Mr Z Feb 10 '19 at 17:46
  • How are you running it? – Arthur B Feb 10 '19 at 21:22
  • AttributeError: module 'pytezos' has no attribute 'key'. running in the python3 cli – Gaia Aug 8 '19 at 19:20
  • same issue here 'pytezos' has no attribute 'key'... – Mack Baise Jan 19 at 9:05
  • 1
    Updated the example – Michael Zaikin Jan 21 at 14:06
3

You may want to read this guide. There is some Python code inside.

1
  • link is dead... can you provide a new link? – Mack Baise Jan 10 at 2:10

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.