Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: Radacoin on April 09, 2013, 07:31:01 AM



Title: Manually generate keys like paper wallet generators do
Post by: Radacoin on April 09, 2013, 07:31:01 AM
I don't trust (online) paper wallet generators. That's why I like to generate keys only using the command line.

I know how to import a private key (with the "importprivatekey" command).

How do I create a private key?

Can I create a temporary private key, that's not stored in my wallet - but only visible on the command line?


Title: Re: Manually generate keys like paper wallet generators do
Post by: jackjack on April 09, 2013, 07:34:48 AM
If hexadecimal private key is ok for you: tr -dc a-f0-9 < /dev/urandom | head -c 64
Otherwise: tr -dc a-f0-9 < /dev/urandom | head -c 64 | xargs ./pywallet.py --info --importhex --importprivkey


Title: Re: Manually generate keys like paper wallet generators do
Post by: Radacoin on April 09, 2013, 07:39:30 AM
If hexadecimal private key is ok for you: tr -dc a-f0-9 < /dev/urandom | head -c 64
Otherwise: tr -dc a-f0-9 < /dev/urandom | head -c 64 | xargs ./pywallet.py --info --importhex --importprivkey

Thanks!

Is there an equivalent for Litecoin?


Title: Re: Manually generate keys like paper wallet generators do
Post by: jackjack on April 09, 2013, 07:42:23 AM
I don't know how Litecoin handles addresses but I think it's the same way, so yeah I think so


Title: Re: Manually generate keys like paper wallet generators do
Post by: Radacoin on April 09, 2013, 10:32:42 AM
Can I use the Bitcoin/Litecoin client to temporarily create a private key that's not put in the wallet.dat? -> because I only need it for my paper wallet.


Title: Re: Manually generate keys like paper wallet generators do
Post by: jackjack on April 09, 2013, 11:20:44 AM
No


Title: Re: Manually generate keys like paper wallet generators do
Post by: deepceleron on April 09, 2013, 11:25:02 AM
vanitygen will make an address and private key that is only printed to the console.


Title: Re: Manually generate keys like paper wallet generators do
Post by: twmz on April 09, 2013, 04:11:09 PM
Can I use the Bitcoin/Litecoin client to temporarily create a private key that's not put in the wallet.dat? -> because I only need it for my paper wallet.

No, but you can use the bitcoin client on a disconnected machine to generate a new address, dump the private key, and then delete the wallet.dat file when you are done.


Title: Re: Manually generate keys like paper wallet generators do
Post by: pc on April 09, 2013, 05:12:33 PM
I threw together a shell script (http://"https://bitcointalk.org/index.php?topic=133220.msg1440779#msg1440779"), based on other posts on this forum, which is what I use. It just uses OpenSSL and some simple shell commands to convert to an address.


Title: Re: Manually generate keys like paper wallet generators do
Post by: HighInBC on April 09, 2013, 05:18:49 PM
I wrote this to create a deterministic wallet based on any string:

Code:
#!/usr/bin/perl
use strict;
use Digest::SHA qw( sha256 );

my $phrase = $ARGV[0];
my $iter   = $ARGV[1] || 10;

my $hash = '';
foreach ( 1 .. $iter ) {
  $hash = sha256( $hash.$phrase );
  my( $key, $address ) = string2keypair( $hash );
  print "$key\t$address\n";
}

sub string2keypair {
  my $key = chr(0x80).shift;
  my $hash = substr( sha256( sha256( $key ) ), 0, 4 );
  $key = unpack( 'H*', $key.$hash );
  $key = `./base58encode.sh $key`;
  `./keyconv $key` =~ m|Address: (1.*)|;
  my $address = $1;
  return ( $key, $address );
}

__END__
./base58encode.sh:
#!/bin/bash
base58=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z})
bc <<<"ibase=16; n=${1^^}; while(n>0) { n%3A ; n/=3A }" |
tac |
while read n
do echo -n ${base58[n]}
done

It uses "keyconv" from vanitygen.


Title: Re: Manually generate keys like paper wallet generators do
Post by: Radacoin on April 10, 2013, 07:25:34 AM
vanitygen will make an address and private key that is only printed to the console.

I am just a little bit paranoid  ;) Afraid of Backdoors and stuff.

This is why I prefer the original client. Was hoping there is a way to generate temporary (private) keys.

Thanks for all your replies guys!


Title: Re: Manually generate keys like paper wallet generators do
Post by: DannyHamilton on April 10, 2013, 01:52:19 PM
vanitygen will make an address and private key that is only printed to the console.

I am just a little bit paranoid  ;) Afraid of Backdoors and stuff.

This is why I prefer the original client. Was hoping there is a way to generate temporary (private) keys.

Thanks for all your replies guys!

A private key is just a 256 bit number generated randomly and converted to Wallet Import Format.

Here's a suggestion:

Flip a well balanced coin 256 times.  Write down a 1 every time it lands on heads.  Write down a 0 every time it lands on tails.

When you are done you will have a private key in binary.

Convert from binary (base 2) to hex (base 16).

Follow these instructions here to convert to Wallet Import Format...

https://en.bitcoin.it/wiki/Wallet_import_format

  • Add a 0x80 byte in front of it, this is the extended key
  • Perform SHA-256 hash on the extended key
  • Perform SHA-256 hash on result of SHA-256 hash
  • Take the first 4 bytes of the second SHA-256 hash, this is the checksum
  • Add the 4 checksum bytes from the previous setp at the end of the extended key from the first step
  • Convert the result from a byte string into a base58 string using Base58Check encoding. This is the Wallet Import Format