From 81a4ecac8169061fc3a303a3dae2c0b7d76da2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Wed, 14 Sep 2022 13:28:06 +0200 Subject: [PATCH] ethereum/keystore2priv.py: getting geth private key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://ethereum.stackexchange.com/questions/12830/how-to-get-private-key-from-account-address-and-password Signed-off-by: Jakub SokoĊ‚owski --- ethereum/keystore2priv.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 ethereum/keystore2priv.py diff --git a/ethereum/keystore2priv.py b/ethereum/keystore2priv.py new file mode 100755 index 0000000..6fef2e9 --- /dev/null +++ b/ethereum/keystore2priv.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +import sys +import binascii +from web3.auto import w3 + +keystore_password = sys.argv[1] +keystore_file_path = sys.argv[2] + +with open(keystore_file_path) as keyfile: + encrypted_key = keyfile.read() + private_key = w3.eth.account.decrypt(encrypted_key, keystore_password) + +print(binascii.b2a_hex(private_key).decode('utf-8'))