Author

Topic: what is grep command in Linux to find hex private key in my .txt file? i saved (Read 200 times)

legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
Additionally, the following regex will find bech32 private keys:

Code:
bc1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{6,87}
I notice {6,87} which AFAIK means string with range 6-87 character. Any reason you chose that range because AFAIK Bech32 address isn't that short.
BIP173 said that addresses can be up to 90 characters long, including the human readable part and separator. The data part after bc1 is at least 6 characters long, and 90 when the length of bc1 is taken out is 87.

Granted, I haven't seen Bech32 addresses that small in practice, because the hash160 has a fixed length.

I see. However, in very rare case the regex could catch another format of private key (such as HEX and Base58) which uses character "b", "c" and "1".

On a side note, which wallet uses Bech32 as format of the private key?
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
On a side note, which wallet uses Bech32 as format of the private key?

Cripes, I must've posted the regex for bech32 address instead  Embarrassed there is no such thing as a Bech32 WIF private key.
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
Additionally, the following regex will find bech32 private keys:

Code:
bc1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{6,87}

I notice {6,87} which AFAIK means string with range 6-87 character. Any reason you chose that range because AFAIK Bech32 address isn't that short.

BIP173 said that addresses can be up to 90 characters long, including the human readable part and separator. The data part after bc1 is at least 6 characters long, and 90 when the length of bc1 is taken out is 87.

Granted, I haven't seen Bech32 addresses that small in practice, because the hash160 has a fixed length.
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
Right private keys are Hex but why there is  K, w, y and .... in private key ? Aha, they turn 128bit binary to hex then find it's related Characters ! and show set of characters !!

If you see a private key with those kind of characters then that is not a hexadecimal formatted key, it is a WIF private key encoded in Base58 (or if it begins with "bc1", bech32).

This regex should find Base58 keys:

Code:
[123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ]{51,52}


Additionally, the following regex will find bech32 private keys addresses:

Code:
bc1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{6,87}
member
Activity: 100
Merit: 30
Stay humble, be cool, make world better place.
I don't understand, every private key is Hex type but they showed with A-Z 0-9 characters

If you are seeing characters from G - Z, then it is NOT hex.  Hex generally only uses numeric digits (0-9) and the first 6 characters of the alphabet in either capital or lowercase form  (A - F and a - f).

Additionally, you only want to use grep if the key is stored as UTF-8 encoded string of characters representing the key in a human-readable format.

How about finding a public or private key in wallet files (specially those are not encrypted) dose this technic works on them?

That depends on the file and which wallet software it came from.  Many wallets store the key in binary format rather than an encoded string.  In that case, using grep will be more complicated and messy and probably isn't the best tool for the job.

Right private keys are Hex but why there is  K, w, y and .... in private key ? Aha, they turn 128bit binary to hex then find it's related Characters ! and show set of characters !!
legendary
Activity: 3416
Merit: 4658
I don't understand, every private key is Hex type but they showed with A-Z 0-9 characters

If you are seeing characters from G - Z, then it is NOT hex.  Hex generally only uses numeric digits (0-9) and the first 6 characters of the alphabet in either capital or lowercase form  (A - F and a - f).

Additionally, you only want to use grep if the key is stored as UTF-8 encoded string of characters representing the key in a human-readable format.

How about finding a public or private key in wallet files (specially those are not encrypted) dose this technic works on them?

That depends on the file and which wallet software it came from.  Many wallets store the key in binary format rather than an encoded string.  In that case, using grep will be more complicated and messy and probably isn't the best tool for the job.
member
Activity: 100
Merit: 30
Stay humble, be cool, make world better place.
grep -E -o '[1234567890abcdefABCDEF]{64}' also does the job and using the -o option, only prints the part of the line that actually matches the private key. This avoids printing extremely large lines or perhaps an entire binary file that happens to have a matching string.

You should probably redirect the output to a file because most terminals' output buffers are fairly small, only holding he last 1000 or so lines of output.

@NotATether
I don't understand, every private key is Hex type but they showed with A-Z 0-9 characters !?
How about finding a public or private key in wallet files (specially those are not encrypted) dose this technic works on them?
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
grep -E -o '[1234567890abcdefABCDEF]{64}' also does the job and using the -o option, only prints the part of the line that actually matches the private key. This avoids printing extremely large lines or perhaps an entire binary file that happens to have a matching string.

You should probably redirect the output to a file because most terminals' output buffers are fairly small, only holding he last 1000 or so lines of output.
newbie
Activity: 9
Merit: 2
thanks a lot, will give it a try and let you know, i tried googling this first only came up for WIF not hex private keys
legendary
Activity: 4354
Merit: 3260
what is grep command in Linux to find hex private key in my .txt file? i saved it somewhere on a backup drive, im not talking about WIF privatekey

Not an expert but I think this will work:

grep -E '[a-fA-F0-9]{64,64}[^a-fA-F0-9]'

newbie
Activity: 9
Merit: 2
what is grep command in Linux to find hex private key in my .txt file? i saved it somewhere on a backup drive, im not talking about WIF privatekey

please help!
Jump to: