3

I want to generate, say 100000 key pairs (address/private key). It should be done offline, without using websites/javascript , with a program on the command line. Of course, the software should use the best way to generate randomness. There is such function on https://www.bitaddress.org , but it's javascript and is not easy to be used by scripts on the command line. Do you know of such software?

  • 2
    You might want to consider deterministic wallets instead of generating list of keys. en.bitcoin.it/wiki/Deterministic_wallet - this way you could avoid maintaining the list of keys – Mikko Ohtamaa Jul 14 '14 at 11:08
  • Thanks for the suggestion, but in this case I actually need the list in order to match addresses to users and spend the amounts. – Hristo Hristov Jul 14 '14 at 14:47
  • Well you can always use the user id as the deterministic seed :) – Mikko Ohtamaa Jul 14 '14 at 18:27
  • That would be easily determined ;) – Hristo Hristov Jul 14 '14 at 19:35
3

A very simple way is to use Vanitygen with the following command:

vanitygen -k -o output.txt -s seeds.txt 1
  • -k keeps it going after it finds a hit
  • -o output.txt will write the key pairs to the file output.txt
  • -s seeds.txt will let you have different seeds. Create this on beforehand
  • 1 is the pattern Vanitygen will look for. Because all addresses start with 1, every hit will be good. Also nice if you want to have nice addresses, like 1Hristo or something. Keep in mind that it will reduce speed ALOT.

Vanitygen creates about 300 kKey/second on my 2010 MBP CPU. With oclvanitygen it is around 750 kKeys/second. The output.txt will reduce the speed a bit, but it will not take a lifetime. I am not on a computer right now on which I can test the command, but it should work.

This will generate key pairs until infinity. If you really want to have exactly 1000000 (or any other number) pairs, try something with a bash for-loop, and something like

vanitygen 1 >> output.txt

Again, I cannot check this right now, so I don't know how the pairs will be in the output.txt, but it should be appended and readable for you.

  • @HristoHristov Out of curiosity: did you use this? If yes, how fast did it go? Was it with ~ 200kKeys/seconds? – Mathias711 Jul 14 '14 at 14:18
  • 1
    It's 1.99 Mkey/s for hard prefixes, but in the case with "1" and writing to output.txt, I'm getting 1K keys per second, which is good enough. It's slower of course, because I guess it's faster to discard an invalid key early, instead of completing the calculations for each key. Anyway, it's fast enough for this case. – Hristo Hristov Jul 14 '14 at 14:43
  • That's a slowing factor I didn't expect. For what I understood from vanitygen is that it creates a key, computes the address and checks it. If good, print the key pair and create new pair (with -k option). If false, create new key. That printing doesnt cost that much resources I imagined. But thanks for the numbers :) – Mathias711 Jul 14 '14 at 14:52
  • 1
    That slowdown is not at all surprising to me: printing and writing to a file is expensive business, especially if the app was only expecting to rarely print values. If it were useful, a version of vanitygen (addressgen?) could be created optimized for this use case. But since it's good enough as-is... – Tim S. Jul 14 '14 at 17:54
0

Here is a discussion about payperwal.py — a single python file with no external module dependencies, and which seems to have been thoroughly tested and verified to produce proper randomity even on machines with broken random number generators.

The python source is available at https://we.lovebitco.in/paperwal.py

It can also create a BIP38-encrypted private key with -e switch.

Usage

## generate unencrypted private/public key pair
python paperwal.py

## public and private key pair with BIP38-encryption
python paperwal.py -e

Once launched the script will ask to press random keys to collect randomity.

The script ran successfully on an android phone (under termux with the python2 package).

❗️ Probably, needless to say that if you plan on using the keys then you must run it on a clean offline machine booted e.g. from a live linux distro with no ethernet/wifi access.

0

You can use bitcoinj — a thoroughly tested Java library written by a google employee as a 20% project. It is used by some wallet apps, such as samurai wallet, bitcoin wallet, greenbits (mycelium plans to migrate to bitcoinj).

  1. Clone the project from https://github.com/bitcoinj/bitcoinj.git
  2. Install maven if missing (e.g. brew install maven on osx or apt install maven on linux), and then sync the project so that all dependencies are satisfied: mvn install (from the project folder).
  3. Use the following code to generate your private/public key pairs.
import org.bitcoinj.core.Address;
import org.bitcoinj.core.DumpedPrivateKey;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.NetworkParameters;

public class GeneratePrivateKey {

    public static void main(String[] args) {

        for (int i=0; i<10000; i++) {
            ECKey key = new ECKey();
            DumpedPrivateKey privKey = key.getPrivateKeyEncoded(NetworkParameters.prodNet());
            System.out.println("private key: " + privKey.toBase58());
            Address pubAddress = new Address(NetworkParameters.prodNet(), key.getPubKeyHash());
            System.out.println("public key: " + pubAddress.toBase58());
            System.out.println("--------------------------------");
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.