I certainly saved my private key in a text file previously, but I don't know where now.

Is there any way to recover my private key?

  • re: "Too broad" votes, I voted "Leave Open" because I feel like a comprehensive answer can be given. See my answer for proof. ;) – Murch Jul 17 '17 at 21:48

If you're programming savvy you could write a small program that searches for the regular expression of a Bitcoin private key. Bitcoin private keys have a very specific format:

They are 51 keys long, start with a '5' and the second letter is either 'H', 'J', or 'K' and use base58 for the remaining 49 letters which excludes the characters 0IOl.

It seems to me that the following regular expression should work to find an uncompressed private key:
5[HJK][1-9A-HJ-NP-Za-km-z]{49} (inspiration: Stackoverflow).

Later, another format was introduced for compressed keys, which has 52 base58 characters, and starts with a 'K' or 'L'. For that format, you should be able to use the following regular expression:


Note that regular expressions can use slightly varying syntax, so you might need to adapt the expression to the programming language or tool that you use. You can generate a few private keys, e.g. with bitaddress.org for testing material. You should probably be more effective if you include word boundary \b symbols before and after the expression.

If you're on a Unix system, these grep commands would find uncompressed and compressed private keys recursively from the directory you're calling from:

grep -r '\b5[HJK][1-9A-HJ-NP-Za-km-z]\{49\}\b' *
grep -r '\b[KL][1-9A-HJ-NP-Za-km-z]\{51\}\b' *

Or search for both of them with this combined pattern:

grep -r '\b[5KL][1-9A-HJ-NP-Za-km-z]\{50,51\}\b' *

To use grep on Windows, you could perhaps find a solution here: What are good grep tools for Windows?


Short Answer: no. Your private key is the seed for your public key which ultimately forms your address. It is double hashed, meaning finding it from your wallet or public key is virtually impossible (in the absence of quantum computing).

Unless you can search for all the .txt files, I am afraid all the coin you might have their is lost.

If you are using a deterministic wallet, then you might have been given a passcode (mnemonic) this might be your only chance to recover the private key.

In future you should try to keep a cold wallet in a secure place.

  • What's so bad about searching all .txt files? ;) See my answer. – Murch Jul 17 '17 at 5:51

I think this is more of an issue with finding the file. Once you have the file (assuming the private key is intact), there should be no problem importing it into a wallet program.

I would recommend moving the remaining BTC from that wallet to a new one because the private key was stored insecurely on your computer, possibly allowing other programs or people to get access to it.

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.