Before you go, check out these stories!

0
Hackernoon logoHow to generate a Bitcoin address — Technical address generation explanation by@tuna-tore

How to generate a Bitcoin address — Technical address generation explanation

Author profile picture

@tuna-toreTuna Tore

software engineer and architect at https://mycrypto.tools

Bitcoin addresses can be created using open-source libraries based on algorithmic hash functions.

Users, most of the time, need more than one Bitcoin addresses to send coins to each other on the Blockchain.

Bitcoin addresses are created based on the concept called Public-key cryptography; private keys are only known to the owner/users.

More details about this: https://en.wikipedia.org/wiki/Public-key_cryptography

In this blog post, you will learn how to generate Bitcoin addresses offline using the algorithmic concepts such as Public key — Private Key, EDCSA, SHA-256 function, RIPEMD-160 hashing, and Binary Bitcoin Address.

This blog will later explain the technical steps/details of creating Bitcoin addresses using cryptographic algorithms and functions.

Bitcoin addresses are composed of alphanumeric characters based on Base58 encoding — doesn’t include 0 (zero), O (capital o), I (capital i), l (lower case L), and the non-alphanumeric characters such as + (plus) and / (slash). More information about Base58 is found at https://en.wikipedia.org/wiki/Base58

Therefore, Bitcoin addresses can only contain the characters from the following alphabet, because Base58 doesn’t allow other characters;

123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz

Nowadays, there are only 3 different address formats used by Bitcoin:

1 — P2PKH (Pay-to-PubkeyHash) — 1KwBRs6CioGM2pFdzQsxyrSZ9ynJQr7Amd — addresses start with a 1
2 — P2SH (Pay to script hash) — 3DnW8JGpPViEZdpqat8qky1zc26EKbXnmM — address start with a 3
3 — Bech32 (SegWit) — bc1qngw83fg8dz0k749cg7k3emc7v98wy0c74dlrkd — addresses start with bc1

The first step is to create a private key, for example, using an open-source Bitcoin library. After this, Bitcoin public keys are created using an algorithm called Elliptic Curve Digital Signature Algorithm.

Graphical Bitcoin Address Generator:

http://royalforkblog.github.io/2014/08/11/graphical-address-generator/

The details of this algorithm can be learned at https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm
https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm

Some of the open source libraries providing this functionality;

https://en.wikipedia.org/wiki/Bouncy_Castle_(cryptography)
https://en.wikipedia.org/wiki/Cryptlib
https://en.wikipedia.org/wiki/Crypto%2B%2B

Private Keys:

- Randomly generated number.
- Only known to the user who created it either through a library, or cryptographic hash functions.
- It shouldn’t be shared with anybody since whoever has the private key can access the funds on the blockchain.
- It is used to sign transactions (sending/receiving Bitcoins).
- It is 32 bytes unsigned integer (256 bit).

Public Keys:

-The public key corresponds to the private key created using the cryptographic functions.
-Public keys can be created using private keys; however, you can’t create Private keys from Public keys. (Public key generation is a one-way function).

Bitcoin Address Generation Steps:

Bitcoin Address Generation Steps

Bitcoin Address details:

-Bitcoin addresses are anonymous, meaning that nobody can know if the address belongs to a known person.
-Bitcoin addresses can be created offline on your computer, meaning that without the internet.
-Bitcoin addresses can be created for free; you don’t need to pay to generate Bitcoin addresses.
-Bitcoin addresses are single use only, and they shouldn’t be reused. Using address more than once creates privacy/security issues that should be avoided.
-Standard address formats; P2PKH (Addresses starts with 1 prefix — Legacy address — case sensitive), P2SH (Addresses starts with 3 prefix — case-sensitive),Bech32 (Addresses starts with bc1 — case insensitive address)-Bitcoin address has a maximum length of 35 characters.
-Can be represented as QR Codes so that your phone can be used to scan codes and send Bitcoins
-Public keys are used to create Bitcoin addresses
-Private keys are used to sign Blockchain-based transactions to send and receive Bitcoins.

Technical Bitcoin Address generation steps:

-Generate a private key using an open-source library.
-Usually, it is better to use a library to handle Private and Public keys for you so that you don’t need to bother with the implementation details.
0: Private Key: a4f228d49910e8ecb53ba6f23f33fbfd2bad442e902ea20b8cf89c473237bf9f
0: Private Key Base58: C6t2iJ7AXA2X1KQVnqw3r7NKtKaERdLnaGmbDZNqxXjk

-Get the related public key based on the generated private key from your open-source library.
-Libraries will also provide you Public keys from its implementation.
1: public key: 03564213318d739994e4d9785bf40eac4edbfa21f0546040ce7e6859778dfce5d4

-Apply SHA-256 hash function on the public key (you should decode hex before SHA-256) created in the step 1.
-Details of the SHA-256 https://en.wikipedia.org/wiki/SHA-2
2: SHA-256 public key: 482c77b119e47024d00b38a256a3a83cbc716ebb4d684a0d30b8ea1af12d42d9

-Apply RIPEMD-160 hash function on the result of step 2 (SHA-256 of public key).
-Details of RIPEMD-160 hash https://en.wikipedia.org/wiki/RIPEMD
3: RIPEMD-160 hashing on the result of SHA-256 public key: 0c2c910a661178ef63e276dd0e239883b862f58c

-Add the version byte prefix to step 3, which is used to define different address formats — 00 is the version byte (0x00 for Main Network).
4: RIPEMD-160 hash with version byte: 000c2c910a661178ef63e276dd0e239883b862f58c

- Apply/Implement two times SHA-256 hash function on step 4 (SHA-256(SHA-256(ripemd-160WithVersionByte))).
5–6: 2 * SHA-256 hash for RIPEMD-160 hash with version byte: c3c0439f33dc4cf4d66d3dd37900fc12597938a64817306b542a75b9223213e0

-Get the first 4 bytes from step 6, which is the output of the second SHA-256 function.
7: CheckSum: c3c0439f

-Add checksum (Step 7) to the end of the RIPEMD-160 hash with version byte (Step 4).
8: 25 Byte Binary Bitcoin Address: 000c2c910a661178ef63e276dd0e239883b862f58cc3c0439f

-Apply and convert binary Bitcoin address using Base58 function to Bitcoin Address format.
-Details of Base58 https://en.wikipedia.org/wiki/Base58
9: Bitcoin Address: 127NVqnjf8gB9BFAW2dnQeM6wqmy1gbGtv

See the address on the Blockchain
127NVqnjf8gB9BFAW2dnQeM6wqmy1gbGtv

Output:

Sample Bitcoin Address Generation steps starting from 0 to 9 — Step 5 and 6 uses SHA-256 hash function:

0: Private Key: a4f228d49910e8ecb53ba6f23f33fbfd2bad442e902ea20b8cf89c473237bf9f
0: Private Key Base58:
C6t2iJ7AXA2X1KQVnqw3r7NKtKaERdLnaGmbDZNqxXjk
1: public key: 03564213318d739994e4d9785bf40eac4edbfa21f0546040ce7e6859778dfce5d4
2: SHA-256 public key: 482c77b119e47024d00b38a256a3a83cbc716ebb4d684a0d30b8ea1af12d42d9
3: RIPEMD-160 hashing on the result of SHA-256 public key: 0c2c910a661178ef63e276dd0e239883b862f58c
4: RIPEMD-160 hash with version byte: 000c2c910a661178ef63e276dd0e239883b862f58c
5–6: 2 * SHA-256 hash for RIPEMD-160 hash with version byte: c3c0439f33dc4cf4d66d3dd37900fc12597938a64817306b542a75b9223213e0
7: CheckSum: c3c0439f
8: 25 Byte Binary Bitcoin Address: 000c2c910a661178ef63e276dd0e239883b862f58cc3c0439f
9: Bitcoin Address: 127NVqnjf8gB9BFAW2dnQeM6wqmy1gbGtv

If you want to learn how to create your Bitcoin address using open-source software and tools then you can attend my course. You can see the details in the following page.

https://www.udemy.com/course/how-to-create-generate-bitcoin-and-ethereum-crypto-addresses-offline

Tags

The Noonification banner

Subscribe to get your daily round-up of top tech stories!