Bit-Currency _ key function implementation

Source: Internet
Author: User

1. Private key--"public key-" bit-currency address

The private key k is multiplied by the elliptic curve to obtain the public key K, and the public key K obtains the bitcoin address by hashing;

2. Private key randomly generated

A long sequence of random bytes is taken out of a cryptographic secure random source, and the SHA256 hash algorithm is used to generate a 256-digit number.

3. Public key generation

The Elliptic curve algorithm is used to generate one-way; {k = k * G}

The public key is a point on the elliptic curve, consisting of a pair of coordinates (X,Y). The public key is usually represented as a number with a prefix of 04 followed by two 256 bits. One of the 256-bit digits is the x-coordinate of the public key, and the other 256-bit number is the y-coordinate. Prefix 04 is used to differentiate between uncompressed public keys, and the compressed format public key is preceded by 02 or 03.

4. Bit-Currency address generation

The public key is obtained by a double hash, the SHA256 hash value is computed with the public key k as input, and the RIPEMD160 hash value is computed with this result, and a number with a length of 160 ratio (20 bytes) is obtained;

Finally see the address also carried out "Base58check" code, Base58 by excluding (0,o,l,i) of uppercase and lowercase letters and numbers, text form to facilitate reading, increase check code to verify;

5. Key format

WIF: Wallet Import format, that is, BASE58 encoding format; 5 opening;

Wif-compressed: Compressed wallet import format, K or l opening;

Compressed private key: The private key is followed by a 01 suffix, which eventually generates wif-compressed;

Non-compressed private key: Only the generated private key, without a suffix, will eventually generate wif;

Compressed public key: only x coordinates are saved, Y coordinates can be obtained by x, but x corresponds to the curve parity two y, so the prefix for compression needs to be 02 for odd, and 03 for even;

Non-compressed public key: with x and y coordinates, prefix 04 followed by two 256-bit digits;

The new wallet uses a compressed format and the old wallet uses a uncompressed format; If a Bitcoin purse implements a compressed-format public key, it will use the compression format to shrink the public key in all transactions. The private key in the wallet will be used to generate the compressed format public key, and the compressed format public key is then used to generate the bit-currency address in the transaction.


Reference: "Proficiency in Bitcoin, Andreas M Antonopoulos (O ' Reilly)." Copyright 2015 Andreas M Antonopoulos, 978-1-449-37404-4. "

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.