Script to retrieve private key from files contained in keystore knowing the associated passphrase.
The following libraries are needed:
pip install pysha3
pip install pyaes
pip install scrypt
pip install eth_keys
According to what has been investigated so far, the process followed for the storage of the key pair in both Ethereum and Quorum follows the following encryption scheme:
Both Ethereum and Quorum store the keys in the Keystore directory and all the required parameters are contained in the json files, which are stored inside this directory. The keystore contains the data necessary to rebuild the private key associated with the public address contained in the json files.
Each json file in the directory has the information associated with each public address. The file contains the parameters to generate a kdf derived key which in turn is used to generate the private key at the output of the aes-128-ctr encryption module. In order to regenerate the key, it is necessary to have the passphrase that the client (or the application internally) has used to build the address.
It should be noted that the ciphertext required as input parameter to the AES module corresponds to the encrypted Ethereum private key.
the result obtained is converted to hexadecimal (decrypted_priv_key_hex).