Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Muhammed Zakir on September 24, 2014, 10:31:29 AM



Title: Is there any way to convert from 1 private key format to another?
Post by: Muhammed Zakir on September 24, 2014, 10:31:29 AM
Hello! Is there any way to convert from 1 private key format to another? Different wallets support different formats and some supports all format. The wallet I am using only supports compressed private key format but I have Base58 Wallet Import format. So is there any way? Thanks!

  ~~MZ~~


Title: Re: Is there any way to convert from 1 private key format to another?
Post by: DannyHamilton on September 24, 2014, 01:09:36 PM
Hello! Is there any way to convert from 1 private key format to another?

Yes.  A private key is just a number.  Different "formats" are just different ways of representing the same number.

Different wallets support different formats and some supports all format. The wallet I am using only supports compressed private key format but I have Base58 Wallet Import format. So is there any way? Thanks!

  ~~MZ~~

Compressed key is a form of Base58 Wallet Import Format.  You shouldn't need to do any conversions.


Title: Re: Is there any way to convert from 1 private key format to another?
Post by: Muhammed Zakir on September 24, 2014, 01:12:27 PM
Hello! Is there any way to convert from 1 private key format to another?

Yes.  A private key is just a number.  Different "formats" are just different ways of representing the same number.

Different wallets support different formats and some supports all format. The wallet I am using only supports compressed private key format but I have Base58 Wallet Import format. So is there any way? Thanks!

  ~~MZ~~

Compressed key is a form of Base58 Wallet Import Format.  You shouldn't need to do any conversions.


Sorry for not posting correctly. I thought Bas58 Wallet Import Format is Uncompressed key as I saw just uncompressed private key in Bitcoin wiki. So is there any way to convert compressed to uncompressed format? ??? And thanks for clarifying it! :)

  ~~MZ~~


Title: Re: Is there any way to convert from 1 private key format to another?
Post by: DannyHamilton on September 24, 2014, 01:28:49 PM
Hello! Is there any way to convert from 1 private key format to another?

Yes.  A private key is just a number.  Different "formats" are just different ways of representing the same number.

Different wallets support different formats and some supports all format. The wallet I am using only supports compressed private key format but I have Base58 Wallet Import format. So is there any way? Thanks!

  ~~MZ~~

Compressed key is a form of Base58 Wallet Import Format.  You shouldn't need to do any conversions.


Sorry for not posting correctly. I thought Bas58 Wallet Import Format is Uncompressed key as I saw just uncompressed private key in Bitcoin wiki. So is there any way to convert compressed to uncompressed format? ??? And thanks for clarifying it! :)

  ~~MZ~~

Compressed and Uncompressed are words that describe how the public key is represented after it is calculated from the private key.

If you convert from a "Compressed Key" private key to an "Uncompressed Key" private key, you are telling the wallet that it should use the private key to calculate an uncompressed public key instead of a compressed public key. Since a bitcoin address is a hash of the public key, this means that changing from a "Compressed Key" private key to an "Uncompressed Key" private key will result in a completely different bitcoin address.

Importing an "Uncompressed Key" private key will not allow you access to any of the bitcoins that were sent to the address that was associated with the "Compressed Key" address.

If you aren't trying to access a particular bitcoin address, then I'm not sure why you'd be importing a private key at all?

If you are certain that you want to import the private key for the "Uncompressed Key" address, then here's what you need to do:

  • Convert from base 58 to bytes (base 16) (http://www.mathsisfun.com/base-conversion-method.html) using the Base58Check symbol chart (https://en.bitcoin.it/wiki/Base58Check_encoding#Base58_symbol_chart)
  • Truncate the trailing 5 bytes from the result of the previous step (this is the Extended Key)
  • Perform SHA-256 hash on the Extended Key
  • Perform SHA-256 hash on the result of the previous step (this is the Extended Checksum)
  • Concatenate the Extended Key and the first 4 bytes of the Extended Checksum
  • Convert the result of the previous step from a byte string into a base58 string using the Base58Check symbol chart (https://en.bitcoin.it/wiki/Base58Check_encoding#Base58_symbol_chart)