<p>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:</p>

<p>They are 51 keys long, start with a '5' and the second letter is either 'H', 'J', or 'K' and use <a href="https://en.bitcoin.it/wiki/Base58Check_encoding" rel="noreferrer">base58</a> for the remaining 49 letters which excludes the characters <code>0IOl</code>.</p>

<p>It seems to me that the following regular expression should work to find an uncompressed private key:<br>
<code>5[HJK][1-9A-HJ-NP-Za-km-z]{49}</code> (inspiration: <a href="https://stackoverflow.com/a/16738021/1364089">Stackoverflow</a>).</p>

<p>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:</p>

<p><code>[KL][1-9A-HJ-NP-Za-km-z]{51}</code></p>

<p>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 <a href="http://bitaddress.org" rel="noreferrer">bitaddress.org</a> for testing material. You should probably be more effective if you include word boundary <code>\b</code> symbols before and after the expression.</p>

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

<pre><code>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' *
</code></pre>

<p>Or search for both of them with this combined pattern:</p>

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

<p>To use <code>grep</code> on Windows, you could perhaps find a solution here: <a href="https://stackoverflow.com/q/87350/1364089">What are good grep tools for Windows?</a></p>

CC BY-SA 3.0
2017-07-17T04:37:43.387Z
2017-07-17T19:35:25.440Z
2017-07-17T19:35:25.440Z
Murch
<p>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.</p>

<p>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. </p>

CC BY-SA 3.0
2017-08-18T14:53:46.167Z
2017-08-18T14:53:46.167Z
Christoph Winter
<p>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). </p>

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

<p>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.</p>

<p>In future you should try to keep a cold wallet in a secure place.</p>

CC BY-SA 3.0
2017-07-17T05:51:23.883Z
What's so bad about searching all .txt files? ;) See my answer.
Murch
CC BY-SA 3.0
2017-07-16T17:40:53.123Z
2017-07-16T17:40:53.123Z
0xsegfault
<p>I certainly saved my private key in a text file previously, 
but I don't know where now.</p>

<p>Is there any way to recover my private key?</p>

<wallet-recovery><recover-private-key>
How can I find a Bitcoin private key that I saved in a text file?
Mohammad Rajabi
# How can I find a Bitcoin private key that I saved in a text file?

(Asked by: username_0 on 2017-07-16)

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?

**Tags:** wallet-recovery, recover-private-key


---

## 3 answers

### Answer by username_1 on 2017-07-17. Score: 12

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:
[KL][1-9A-HJ-NP-Za-km-z]{51}
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?


---

### Answer by username_2 on 2017-08-18. Score: 0

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.


---

### Answer by username_3 on 2017-07-16. Score: -1

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.

> **Comments:**
> **username_1**: What's so bad about searching all .txt files? ;) See my answer.  

---

