I'm using geth over rpc in my php script for a website.

In my script I've created a random passphrase that I store in a file so I can use it later to unlock the account.

So, to keep thing simple I create it using this code :

$myfile = fopen($basepath.hash('sha256', $somethingToIdentifyTheAccountInAUniqueWay, "w"));
$passkey = bin2hex(openssl_random_pseudo_bytes(256));
$new_address = $eth->personal_newAccount($passkey);
fwrite($myfile, $passkey);

and then I unlock it with :

$passphrase =  fread($myfile,filesize($filepath));
$eth->personal_unlockAccount($address, $passphrase, 5);

The system works, but for some reason 6 of my approximately 30k address are unable to unlock, even manually inside the geth console using the passphrase I got from the file...

The error is :

Error: could not decrypt key with given passphrase

Is there something I can try to unlock the account? Somewhere I can try to track the problem? We do backup each 30min and nothing have change from creation to now. I dont know where to look anymore as everything seems fine... I even try empty passphrase or php error code that could possibly been registered in the variable in case something went wrong somewhere...

1 Answer 1


If you don't have the correct passphrase then there's nothing you can do to unlock the account.

It's hard to say what could have happened without seeing the rest of your code, and particularly how you created the password and the filename. For example, you might have a logic bug that has caused you to assign the same filename twice, and overwrite the previous one.

One thing you might want to try is retyping the password you see in the file into a new file, then running a hashing tool against it (md5sum would do) to make sure the password in the file doesn't somehow include some kind of non-printable character. You could also run md5sum (or whatever other hashing tool you're using) against your current directory and what you see in your backups, then use diff to compare the two directory listings and see if any of your passwords ever change, which could be a sign of a software bug or filesystem corruption.

Finally, I know it's probably too late to be saying this and it's easy to be wise after the event, but you should probably be testing unlocking the files from your backups, before you start using them. You may also want to look into creating addresses deterministically based on a root seed, so you don't have to manage 30,000 passwords.

  • I've update my post to add some code, there is nothing more then that. by looking my backup, the file containing the password is exactly the same as the day it was created... non-printable character is a good thinking, I've try writing all of it manually and it didn't work tough. Well, with all the character I may have done an error myself so I'm going to try again, i'll keep you update after some try
    – Skarn
    Aug 29, 2017 at 14:16
  • After some try, it still don't unlock :( Diff show everything is the same... and I'm sure I'm using the passphrase from the address creation. don't know what to do anymore... but thanks for your suggestions.
    – Skarn
    Aug 31, 2017 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.