Pages:
Author

Topic: [overview] Recover Bitcoin from any old storage format - page 4. (Read 8689 times)

legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
newbie
Activity: 26
Merit: 3
Hi All

in the following script where do input the private key with the missing characters? is it Bitcoin Public Key?

That is not a script, it is an old helper class to be used in different places within the program (from one of my old projects). It doesn't have any option to accept any "private" keys.
If you want to know how things are done you have to check the link I previously posted to the project called the FinderOuter.
For quick reference the entry point is here where "key" is the base58 encoded private key string containing missing characters that are replaced by a character defined by the missingChar char.
Initialize() method converts what it can from the given string to base-256 and sets the missing indexes. Then depending on key type (compressed or uncompressed) a LoopComp() or LoopUncomp() is called where different base-58 characters are placed in missing indexes and they are checked against the checksum. The rest are SHA-256 details.

hi In the link you have provided where do input the private key with the missing characters?
legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
Hi All

in the following script where do input the private key with the missing characters? is it Bitcoin Public Key?

That is not a script, it is an old helper class to be used in different places within the program (from one of my old projects). It doesn't have any option to accept any "private" keys.
If you want to know how things are done you have to check the link I previously posted to the project called the FinderOuter.
For quick reference the entry point is here where "key" is the base58 encoded private key string containing missing characters that are replaced by a character defined by the missingChar char.
Initialize() method converts what it can from the given string to base-256 and sets the missing indexes. Then depending on key type (compressed or uncompressed) a LoopComp() or LoopUncomp() is called where different base-58 characters are placed in missing indexes and they are checked against the checksum. The rest are SHA-256 details.
newbie
Activity: 26
Merit: 3
Hi All

in the following script where do input the private key with the missing characters? is it Bitcoin Public Key?

Using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Text;


namespace CommonLibrary
{
    ///
    /// https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses
    ///

    public class BitcoinConversions
    {
        ///
        /// Satohi is the smallest amount of bitcoin, 10^-8
        ///

        public const decimal Satoshi = 0.00000001m;


        ///
        /// Characters used in Base58Encoding which is all chars excluding "0OIl"
        ///

        private const string Base58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";




        ///
        /// Converts a hex string to intiger.
        ///

        /// hex value to convert.
        ///
        //public static UInt32 HexToInt(string hex)
        //{
        //    byte[] ba = HexToByteArray(hex);
        //    if (!BitConverter.IsLittleEndian)
        //    {
        //        ba = ba.Reverse().ToArray();
        //    }
        //    // Prevent out of range exception by adding zeros.
        //    if (ba.Length < 4)
        //    {
        //        ba = ba.Concat(new byte[4 - ba.Length]).ToArray();
        //    }
        //    return BitConverter.ToUInt32(ba, 0);
        //}




        ///
        /// Converts a hex string to bye array.
        ///

        /// hex to convert.
        /// byte array of hex
        public static byte[] HexToByteArray(string hex)
        {
            int NumberChars = hex.Length;
            byte[] bytes = new byte[NumberChars / 2];
            for (int i = 0; i < NumberChars; i += 2)
                bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
            return bytes;
        }


        ///
        /// Converts a byte array to hex string.
        ///

        /// byte array to convert.
        ///
        public static string ByteArrayToHex(byte[] b)
        {
            StringBuilder result = new StringBuilder();
            for (int i = 0; i < b.Length; i++)
            {
                result.Append(b.ToString("x2"));
            }
            return result.ToString();
        }




        ///
        /// Converts the Hash160 (RIPEMD-160) to Base58 encoded string.
        ///

        /// Hash160 string value.
        /// Base58 Encoded result.
        public static string Base58ToHash160(string data)
        {
            // Decode Base58 string to BigInteger
            BigInteger intData = 0;
            for (var i = 0; i < data.Length; i++)
            {
                intData = intData * 58 + Base58Chars.IndexOf(data);
            }


            // Encode BigInteger to byte[]
            // Leading zero bytes get encoded as leading `1` characters
            var bData = intData.ToByteArray();
            if (BitConverter.IsLittleEndian)
            {
                bData = bData.Reverse().ToArray();
            }
            bData = bData.SkipWhile(b => b == 0).ToArray();
            var hash160 = BitConverter.ToString(bData).Replace("-", "").ToLower();
            // Remove checksum (4 bytes = 8 last chars)
            return hash160.Remove(hash160.Length - Cool;
        }




        ///
        /// Computes the hash value of the specified byte array.
        ///

        /// byte array to compute hash of.
        ///
        private static byte[] DoubleShaByte(byte[] b)
        {
            using (SHA256 sha = new SHA256Managed())
            {
                byte[] hash1 = sha.ComputeHash(b);
                byte[] hash2 = sha.ComputeHash(hash1);


                return hash2;
            }
        }


        ///
        /// Returns Transaction Id for the given Raw Transaction hex.
        ///

        /// Raw Transaction hex.
        /// Transaction Id
        public static string GetTxId(string txHex)
        {
            byte[] ba = HexToByteArray(txHex);
            byte[] sha2x = DoubleShaByte(ba);


            return ByteArrayToHex(sha2x.Reverse().ToArray());
        }




        ///
        /// Converts Public Key to Hash160 (RIPEMD-160)
        /// A.K.A. payload
        ///

        /// Bitcoin Public Key
        /// hash160 (RIPEMD-160)
        public static byte[] PubKeyToHash160(string pubKey)
        {
            using (SHA256 sha = new SHA256Managed())
            {
                byte[] pubKeyBytes = HexToByteArray(pubKey);


                // 2. Perform Sha256 hashing on public key
                byte[] hash1 = sha.ComputeHash(pubKeyBytes);


                // 3. Perform RIPEMD-160 hashing on step 2
                using (RIPEMD160 r160 = new RIPEMD160Managed())
                {
                    byte[] hash2 = r160.ComputeHash(hash1);


                    return hash2;
                }
            }
        }


        ///
        /// Converts Hash160 (RIPEMD-160) to Base58 bitcoin Address.
        ///

        /// Hash160 (RIPEMD-160) bytes
        /// Base58 encoded bytes
        public static string Hash160ToBase58(byte[] hash160)
        {
            // 4. Add version byte in front of RIPEMD-160 hash (0x00 for Main Network)
            byte[] ver = { 0x00 };
            byte[] hash160Extended = ver.Concat(hash160).ToArray();


            // 5&6. Perform SHA-256 hash on the extended RIPEMD-160 result x2
            byte[] sha2x = DoubleShaByte(hash160Extended);


            // 7. The first 4 bytes are address checksum
            byte[] checkSumByte = new byte[4];
            checkSumByte[0] = sha2x[0];
            checkSumByte[1] = sha2x[1];
            checkSumByte[2] = sha2x[2];
            checkSumByte[3] = sha2x[3];


            // 8. 25-byte binary Bitcoin Address = RIPEMD-160 extended + Checksum
            byte[] hash160WithCheckSum = hash160Extended.Concat(checkSumByte).ToArray();


            return Hash160WithCheckSumToBase58(hash160WithCheckSum);
        }
        public static string Hash160ToBase58(string hash160)
        {
            byte[] hash160Bytes = HexToByteArray(hash160);
            return Hash160ToBase58(hash160Bytes);
        }


        ///
        /// Converts hash to Base58 Encoded string.
        ///

        /// 1-byte_version + hash_or_other_data + 4-byte_check_code
        /// Base58 encoded result
        public static string Hash160WithCheckSumToBase58(byte[] hash)
        {
            // Decode byte[] to BigInteger
            BigInteger intData = hash.Aggregate(0, (current, t) => current * 256 + t);


            // Encode BigInteger to Base58 string
            StringBuilder result = new StringBuilder();
            while (intData > 0)
            {
                var remainder = (int)(intData % 58);
                intData /= 58;
                result.Insert(0, Base58Chars[remainder]);
            }


            // Append '1' for each leading 0 byte
            for (var i = 0; i < hash.Length && hash == 0; i++)
            {
                result.Insert(0, '1');
            }


            return result.ToString();
        }
        public static string Hash160WithCheckSumToBase58(string hash)
        {
            byte[] hashByte = HexToByteArray(hash);
            return Hash160WithCheckSumToBase58(hashByte);
        }


        ///
        /// Converts Public Key to Base58 encoded Bitcoin Address.
        ///

        /// Bitcoin Public Key.
        /// Base58 encoded Bitcoin Address.
        public static string PubKeyToBase58(string pubKey)
        {
            byte[] hash160 = PubKeyToHash160(pubKey);


            string base58 = Hash160ToBase58(hash160);


            return base58;
        }
    }
}
jr. member
Activity: 119
Merit: 1
Thanks is there a tool i can use to recover ? as i must have missed a few characters off or could someone help me via private message  as i do not want to disclose it on here !!

You could use The FinderOuter. Compile it from source code or download the released version, run it offline. The program only has 2 options for now and you need the second option ("Missing Base58"). I believe the rest is self explanatory.
It should take a second to find the right key(s) with 3 missing characters.

Disclaimer: I am the developer of The FinderOuter. The project is brand new and in beta, I'll try to add new features (eg. not knowing the missing character locations) to it soon.

Where can I download your software ( The FinderOuter ) for testing?
legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
Thanks is there a tool i can use to recover ? as i must have missed a few characters off or could someone help me via private message  as i do not want to disclose it on here !!

You could use The FinderOuter. Compile it from source code or download the released version, run it offline. The program only has 2 options for now and you need the second option ("Missing Base58"). I believe the rest is self explanatory.
It should take a second to find the right key(s) with 3 missing characters.

Disclaimer: I am the developer of The FinderOuter. The project is brand new and in beta, I'll try to add new features (eg. not knowing the missing character locations) to it soon.
legendary
Activity: 3290
Merit: 16489
Thick-Skinned Gang Leader and Golden Feather 2021
Thanks is there a tool i can use to recover ? as i must have missed a few characters off or could someone help me via private message  as i do not want to disclose it on here !!
Just another warning: you shouldn't disclose your private key through PM either!
You could make an exception if you really trust the person and your balance isn't high, but as always: stay vigilant.
newbie
Activity: 26
Merit: 3
1) i have a private key which begins with K and is 49 Characters long base58
2) i have a private key which begins with K and is 54 Characters long base58
PS: If i use the the script on here and use this in github https://pastebin.com/S8WARrRn? will it work or do i have to use it on pastebin to run the script ?

no it won't work because it is hard-coded for a special case and none of the settings match your issue.
- only has a fixed number of missing characters: 5
- is an uncompressed private key (starting with 5)
- you know the location of missing characters

your private keys are compressed that start with K and their length should have been 52. and you don't seem to know the location of the missing characters.
now are you sure what you have are actually private keys? how did you lose the rest of the characters? for example if it is from the end then recovering it is going to be trivial as it would take a fraction of a second.

p.s. if my calculation is right you have to check 22.94 billion keys if you miss 3 characters and don't know their location.

Thanks is there a tool i can use to recover ? as i must have missed a few characters off or could someone help me via private message  as i do not want to disclose it on here !!
jr. member
Activity: 119
Merit: 1

Could someone kindly help as i could use the BTC's right now!!!!!
PS: If i use the the script on here and use this in github https://pastebin.com/S8WARrRn? will it work or do i have to use it on pastebin to run the script ?
Many Thanks
J

Interestingly, something similar tools for private key recovery is available under PYTHON_27, maybe on Github ?
legendary
Activity: 3472
Merit: 10611
1) i have a private key which begins with K and is 49 Characters long base58
2) i have a private key which begins with K and is 54 Characters long base58
PS: If i use the the script on here and use this in github https://pastebin.com/S8WARrRn? will it work or do i have to use it on pastebin to run the script ?

no it won't work because it is hard-coded for a special case and none of the settings match your issue.
- only has a fixed number of missing characters: 5
- is an uncompressed private key (starting with 5)
- you know the location of missing characters

your private keys are compressed that start with K and their length should have been 52. and you don't seem to know the location of the missing characters.
now are you sure what you have are actually private keys? how did you lose the rest of the characters? for example if it is from the end then recovering it is going to be trivial as it would take a fraction of a second.

p.s. if my calculation is right you have to check 22.94 billion keys if you miss 3 characters and don't know their location.
newbie
Activity: 26
Merit: 3
Hi All

I just wanted some help form anyone i am not sure the balance of my private key but that is not the main issue....

The main issues are as follows
1) i have a private key which begins with K and is 49 Characters long base58
2) i have a private key which begins with K and is 54 Characters long base58

I am not sure how to resolve this and kind the actual private key i have even wrote BTC address down wrong...

Could someone kindly help as i could use the BTC's right now!!!!!
PS: If i use the the script on here and use this in github https://pastebin.com/S8WARrRn? will it work or do i have to use it on pastebin to run the script ?
Many Thanks
J
legendary
Activity: 3500
Merit: 6320
Crypto Swap Exchange
Just because I had this happen.

When restoring from very old core wallets (wallet.dat) keep in mind that you might have to use the same OS (Linux / Win / Mac) as the original file.
Not sure why, but I could not import a 0.7.1 wallet.dat from a Linux box into a Windows one. Gave a corrupt error and shutdown.

Popped the file into a CentOs like it was originally on and no issues.
Moved the updated wallet.dat back to the Windows machine and all was good. So it was something with the older version of the wallet.dat from a foreign OS
I can't think why there would be a reason for this to be happening, because as far as I know the current Bitcoin Core versions should be fully backward compatible with older versions, and the wallet.dat doesn't hold any information on what OS was used during creation. However, alternatively you could have imported the private key instead of running the original OS that the wallet was created on, unless you haven't backed up your private key. There's the other option of importing your seed which was generated at the creation of the wallet too. AFAIK, there should not be any problems with importing older wallet.dat files into newer operating systems even if they're different.

Personally, I don't rely on the wallet.dat file, and have backups of my private keys which I took care in making sure they never touched a electronic device, and aren't stored in plain text. Although, I still have hot wallets like anyone else, but the majority of my Bitcoin is stored via these offline generated private keys.

I believe a certain version of Electrum abandoned backwards compatibility a few years ago, but I'm not sure if I'm recalling that correctly, and even then I don't think Bitcoin Core in its history has rejected backward compatibility. Of course, even if older software isn't backward compt

I know it should not matter, but it did.

And the only reason I even thought about going back to the Linux box was there was a post someplace (here / reddit / somewhere) with somebody having the same issue that I saw a long time ago. So there were at least 2 people with the issue before this. The one who had it and the one who told him the solution. So, since also happened to me, I figured it was worth a mention.

The only thing I can come up with, and this is a stretch, is that there was a very minor difference with some versions of the DB, depending on the OS and how you compiled it.
But that is really pulling something out of the air and grasping for a reason.

-Dave

staff
Activity: 3304
Merit: 4115
Just because I had this happen.

When restoring from very old core wallets (wallet.dat) keep in mind that you might have to use the same OS (Linux / Win / Mac) as the original file.
Not sure why, but I could not import a 0.7.1 wallet.dat from a Linux box into a Windows one. Gave a corrupt error and shutdown.

Popped the file into a CentOs like it was originally on and no issues.
Moved the updated wallet.dat back to the Windows machine and all was good. So it was something with the older version of the wallet.dat from a foreign OS
I can't think why there would be a reason for this to be happening, because as far as I know the current Bitcoin Core versions should be fully backward compatible with older versions, and the wallet.dat doesn't hold any information on what OS was used during creation. However, alternatively you could have imported the private key instead of running the original OS that the wallet was created on, unless you haven't backed up your private key. There's the other option of importing your seed which was generated at the creation of the wallet too. AFAIK, there should not be any problems with importing older wallet.dat files into newer operating systems even if they're different.

Personally, I don't rely on the wallet.dat file, and have backups of my private keys which I took care in making sure they never touched a electronic device, and aren't stored in plain text. Although, I still have hot wallets like anyone else, but the majority of my Bitcoin is stored via these offline generated private keys.

I believe a certain version of Electrum abandoned backwards compatibility a few years ago, but I'm not sure if I'm recalling that correctly, and even then I don't think Bitcoin Core in its history has rejected backward compatibility. Of course, even if older software isn't backward compt
legendary
Activity: 3500
Merit: 6320
Crypto Swap Exchange
Just because I had this happen.

When restoring from very old core wallets (wallet.dat) keep in mind that you might have to use the same OS (Linux / Win / Mac) as the original file.
Not sure why, but I could not import a 0.7.1 wallet.dat from a Linux box into a Windows one. Gave a corrupt error and shutdown.

Popped the file into a CentOs like it was originally on and no issues.
Moved the updated wallet.dat back to the Windows machine and all was good. So it was something with the older version of the wallet.dat from a foreign OS

Did a 2nd time to verify that I was just not being stupid and the same thing happened.

Should probably spend some time doing some other checks but I'm a slacker not that motivated  Grin

-Dave
legendary
Activity: 3472
Merit: 10611
What if I store my privkeys and all these wallets over CLOUD services?

cloud services can never be an option and here is the problem, when you store your private keys on a cloud server you need to encrypt it first. and we are talking about a strong encryption which means you now have to create a backup of that strong (long and random with symbols,...) password so we are back at square one of you looking for a way to store something!
not to mention you now have to also create a backup of the login details of that cloud service somewhere. you can't just click save password in your browser or write it in a text file stored on your hard disk. and this password has to be equally strong.
and finally you should think about the risk of them closing your account for whatever reason. you will have no control over that.
legendary
Activity: 3290
Merit: 16489
Thick-Skinned Gang Leader and Golden Feather 2021
- If I store on an online cloud service!
In general, it's a bad idea to store private keys online.

Quote
- If I store on an offline cloud service!
I'm not sure how an offline cloud service would work: if it's offline, you can't store data.

Quote
And if I keep them over telegram (through their saved messages feature)
Again: it's a bad idea to store private keys online.

Quote
but somehow lose control to my number (or else it gets automatically allocated to someone else)? Will I still be able to get back my telegram ever or is it gone with all my data I used to bookmark and save in it?
I don't think this is the right topic to discuss specific third party account recoveries.
legendary
Activity: 3052
Merit: 1273
One of the most important questions I want to ask:

What if I store my privkeys and all these wallets over CLOUD services?

Based on this, 2 more questions:
- If I store on an online cloud service!
- If I store on an offline cloud service!

And if I keep them over telegram (through their saved messages feature) but somehow lose control to my number (or else it gets automatically allocated to someone else)? Will I still be able to get back my telegram ever or is it gone with all my data I used to bookmark and save in it?
legendary
Activity: 3052
Merit: 1273
Don't forget micro and standard SD's as well! I'd go with USB, SSD, HDD, even hybrids, but not convinced about discs and tapes. Too easily damaged in my opinion.

Fair point, but discs (especially M-disc) and tapes generally have longer life-span. While it's easily damaged, IMO it's expected user know who bother use those have knowledge to store those properly.

What about Blu-ray DVDs?
I used to play with these things way before but now less likely to store on them as I find them too much vulnerable towards getting corrupt or damaged. Any simple yet favorable to any conditions kinda device that'd actually deliver to store these kind of things without having to fear a lot about it? I don't want to think a lot saving my entire savings into a device I believe I could rely upon.
legendary
Activity: 1722
Merit: 2213
Finally I'd recommend never making just 1 backup (this is a single point of failure still), make multiple on cheap USBs for a distributed backup system instead.

It'd also be better to also use more than one type of data storage medium in each location, ideally a combination of USB drives, SSDs, HDDs, M-Disc DVDs, and LTO tapes if you have a tape drive. I would be a little worried if I had to rely solely on flash memory.

Don't forget micro and standard SD's as well! I'd go with USB, SSD, HDD, even hybrids, but not convinced about discs and tapes. Too easily damaged in my opinion.
legendary
Activity: 3472
Merit: 1724
Finally I'd recommend never making just 1 backup (this is a single point of failure still), make multiple on cheap USBs for a distributed backup system instead.

It'd also be better to also use more than one type of data storage medium in each location, ideally a combination of USB drives, SSDs, HDDs, M-Disc DVDs, and LTO tapes if you have a tape drive. I would be a little worried if I had to rely solely on flash memory.
Pages:
Jump to: