I'm just figuring out how to create my personal keypair in an isolated computer. By this way all the solutions that I've found are installing software from third parties. Even if I choose to use geth, you would need an inet connection to install it in your computer.


1.- Is there a way to make this keypair by myself? for example through gpg or openssl 2.- What are the structure of these keypairs? I suppose that there is much more than a 64 hex string to take into account in order to generate one priv key.

Thanks in advance!!


You can generate a secp256k1 keypair using OpenSSL, but converting that to an Ethereum address is a bit tricky.

The private key is actually just a random 32-byte number (actually it needs to be a bit smaller than that, but there's almost no chance you'll pick a bad one)

The issue is that converting a secp256k1 public key into an address requires the keccak-256 hash function, which is not commonly used and thus will not be built into OpenSSL or GPG. The good news is since this step only uses public information, it can be done on an insecure computer.

(Much of the following is adapted from https://kobl.one/blog/create-full-ethereum-keypair-and-address/)

Now for the process:

  1. Generate an ECDSA keypair with OpenSSL:

    • openssl ecparam -name secp256k1 -genkey -noout

      -----BEGIN EC PRIVATE KEY----- MHQCAQEEIC9jw7nfGyE2EmMzP0z4kIFpaET12WcyMvzltYNMu4iNoAcGBSuBBAAK oUQDQgAEAktsaI/qccPP4lYqpCOVG1fC54/5vQoO1TvfjVcOeSOwM2BGLgzyK80D ufdH9mUbOC2WtxYxCX5vOIy+b+VD5w== -----END EC PRIVATE KEY-----

  2. Get the raw public and private keys and save to a file:

    • openssl ecparam -name secp256k1 -genkey --noout | openssl ec -text -noout >> keypair.prv

      read EC key Private-Key: (256 bit) priv: d2:17:23:e4:e5:30:e5:94:97:11:70:97:e4:ac:e0: 0b:1c:2e:fa:14:76:5a:55:75:00:e3:4d:96:d9:57: d8:67 pub: 04:28:13:c1:5f:59:d1:c8:f7:41:7a:ad:0b:60:d6: 01:22:5d:51:2a:e8:3b:79:f3:a7:8f:f3:73:7c:25: 28:84:1f:12:97:ed:1f:5e:a3:22:c5:d3:f4:a7:c9: 39:fd:53:93:87:20:96:0e:3b:7b:0d:b2:96:ba:c0: 43:72:fb:6d:b3 ASN1 OID: secp256k1

  3. The private key is just the to section with colons and whitespace stripped off:

    • cat keypair.prv | grep priv -A 3 | tail -n +2 | tr -d ":\n[:space:]" >> privatekey.prv
  4. Do the same for the public key, but also strip off the leading 0x04

    • cat keypair.prv | cat key.prv | grep pub -A 5 | tail -n +2 | tr -d ":\n[:space:]" | sed "s/^04//g" >> publickey.pub

Then you should write down the private key somewhere safe, and move the public key to a networked computer.

You then need to use an implementation of Keccak256 to hash the public key. A good python module is https://pypi.python.org/pypi/pysha3.

Then hash the address and take the last 20 bytes (40 characters). This is your address.

For example, if your raw public key is 2813c15f59d1c8f7417aad0b60d601225d512ae83b79f3a78ff3737c2528841f1297ed1f5ea322c5d3f4a7c939fd53938720960e3b7b0db296bac04372fb6db3 as in the example, then you would derive your address in python as

import binascii
from sha3 import keccak256
k = keccak256()
pubkey = binascii.unhexlify("2813c15f59d1c8f7417aad0b60d601225d512ae83b79f3a78ff3737c2528841f1297ed1f5ea322c5d3f4a7c939fd53938720960e3b7b0db296bac04372fb6db3")
address = "0x"+k.hexdigest()[24:]

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