0

When I load the JSON file of the wallet into MyEtherWallet, how does it determine if the passphrase is correct or incorrect? After I initially give a passphrase to encrypt my wallet's private key, is the mapping between the decrypted and encrypted private keys stored anywhere?

2

I don't know how MyEtherWallet does it, but this way seems logical: The keystore contains the address belonging to the encrypted private key. After you received the private key as a result of the decryption, you can derive a public key and finally an address of it. You can compare the resulting address with the address stored within the keystore to proof if the decrypted private key is correct.

edit

I have looked into the structure of a keystore file and saw that a message authentication code (MAC) is specified. You can compare the mac given with the mac you derived to proof the decryptions validity. By looking into the pyethereum code, I have found the following lines of code which do this:

mac1 = sha3(derivedkey[16:32] + ctext)
mac2 = decode_hex(cryptdata["mac"])
if mac1 != mac2:
    raise ValueError("MAC mismatch. Password incorrect?")
  • 1
    I believe that geth keystores used to do what you said at first. Both ways work, but MACs are significantly faster to check – Tjaden Hess Aug 23 '18 at 21:52

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.