bitcoin

Bitcoin

How to generate Bitcoin addresses - Technical explanation and online course

Author: Tuna Tore - December, 1 2019

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; Even though public keys don't need to be kept as a secret, private keys have to be known only by the owners/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.

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

Graphical Bitcoin Address Generator:
http://royalforkblog.github.io/2014/08/11/graphical-address-generator/

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 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.

bitcoinaddress generation steps

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 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.
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
----------------------------------------------------------------------------------------------------------------------------

When it comes to creating Bitcoin and Ethereum public and private key pairs, security becomes crucial. Having the right software code gives users the confidence to create as many as Bitcoin, and Ethereum addresses offline without the need to download any commercial software on their computers or mobile phones. This is what we provide here to our users at mycrypto.tools — increasing the security of cryptocurrency key generation to a maximum level, which is the offline key generation for Bitcoin and Ethereum coins.

Tuna Tore founder of mycrypto.tools



Learn more about our cryptocurrency course

demo
COURSE

Cryptocurrency private-public address generation course for you

Benefits of attending this cryptocurrency course are listed below:
  • Complete ownership of your public and private keys for Bitcoin and Ethereum cryptocurrencies.
  • Complete ownership of the source codes to create private keys — open-source software.
  • Understand how the addresses are created step by step (with a simplified language) without depending on external parties such as companies providing software wallets or cold wallets also named as cold storage.
  • You will be able to encrypt your private keys and store them in a safe place without the need to share anywhere, which provides you the opportunity to send some cryptocurrency to your offline address and store it for many years in a safe location.
  • You don't need to depend on anyone apart from following this course — which is simplified and based on open-source software — while creating your cold/paper wallets.
  • Understand Bitcoin and Ethereum, Blockchain, Crypto Wallet Types, and history of cryptocurrencies.

Learn more about our cryptocurrency course