Bitcoin address and key

    There is no concept of an account in Bitcoin, so how do you determine that your Bitcoin is your Bitcoin, or how do you prove that you are you?
    This is mainly applied to cryptography. To give a simple example, Xiaowang transfers 100btc to Xiaozhang. In fact, he puts the 100btc on the blockchain, and then uses the lock script to lock the money to Xiaozhang 's address , and Xiao Zhang only needs to provide the signature and public key to use the money; in the same way, when Xiao Zhang wants to spend the money, he also locks the btc to a new address, and the next person unlocks it to spend; then here is a small What is Zhang's address? This time I will mainly introduce the concepts of wallet and address in Bitcoin.

   
    public and private keys

    In Bitcoin, the private key is equivalent to the password, and the public key is equivalent to your account number; when someone transfers money to your public key address, you use the private key to withdraw money.
    The private key is just a randomly selected number. If we write one by ourselves, the security is definitely not easy to be cracked. After all, it is related to money. This step is very important. Generally, a long string of random bytes is extracted from a cryptographically secure random source. It uses the SHA256 hashing algorithm to easily generate a 256-bit number.
    The public key can be calculated from the private key through the elliptic curve algorithm, which is an irreversible process: K = k * G . where k is the private key, G is a constant
point , and K is the resulting public key. The reverse operation, called "finding the discrete logarithm" - knowing the public key K to find the private key k - is very difficult, like trying
all possible values ​​of k, that is, brute force search . The difficulty of reverse operation can be simply understood as, you know that the public key is 1024, 1024=k*G, then can you figure out what k is? Of course this is relatively simple, what if the public key K is a very large number? You can wonder what the outcome will be.
    
    bitcoin address

    What is the address of Xiao Zhang mentioned above, and now I will explain how he generated it.

1. The purpose of adding a version is to clarify the data type that needs to be encoded. The data type is as follows:

2. The check code is added mainly to detect errors in the transcription process;
3. What is Base58check?
    Let's start from the base,
    Binary: 0, 1
    Decimal: 0~9
    Hexadecimal: 0~9, A~F
    Base64: 0~9, a~z, A~F, and a symbol (for example, -, +)
    Base58: is a subset of the Base64 encoding format, which also uses uppercase and lowercase letters and 10 numbers, but discards some characters that are easily misreadable and confusing in specific fonts
    . Specifically, Base58 does not contain 0 (digital 0), O (uppercase ⺟o), l (lowercase ⺟L), I (uppercase ⺟i),
    and "+" and "/" in Base64 character.
    Base58Check: It is a Base58 encoding format commonly used in Bitcoin, and an error check code is added to check for errors in data transcription. The checksum is 4
    bytes long and is added after the data to be encoded.
The final generated address is your account.

    key format
Both public and private keys can be encoded in a variety of formats. After a key is encoded in a different format, although the result may look different, the number encoded in the key does
not change. These different encoding formats are mainly used to facilitate people to use and identify keys without errors.
private key format
    It is possible to convert between different formats.
public key format
    Public keys can also be represented in a number of different formats, the most important being that they are classified as uncompressed or compressed public keys.
    A public key is a point on an elliptic curve consisting of a pair of coordinates (x, y). The public key is usually represented by the prefix 04 followed by two 256-bit
numbers . One of the 256-bit numbers is the x-coordinate of the public key, and the other 256-bit number is the y-coordinate. The prefix 04 is used to distinguish the public key in the uncompressed format, and the
public key starts with 02 or 03.
                                                                        public key=04xy
    Compressed public keys are introduced to reduce the number of bytes in Bitcoin transactions, thereby saving disk space for nodes running the blockchain database. According to the elliptic curve formula, it can be analyzed that as long as x is known, y can be calculated, so y can be omitted when storing the public key, so that the size of the public key is reduced by 256 bits. But there is a problem that the value of y has two possibilities, positive and negative, which correspond to the odd and even numbers of y corresponding to the elliptic curve. Therefore, in order to distinguish the two possible values ​​of the y coordinate, when we generate the public key in the compressed format, if y is If y is even, use 02 as the prefix; if y is odd, use 03 as the prefix. In this way, the corresponding y coordinate can be correctly deduced according to the x value given in the public key, so that the public key can be decompressed into a complete point coordinate on the elliptic curve.
    

Compressed private key
    The public key is converted into a bitcoin address, and the resulting address will be different from the address generated by the public key in uncompressed format. However, the private keys for these two different bitcoin addresses are the same.
    However, not all clients support compressed public keys, so those newer clients that do support compressed public keys have to consider how to handle those from older uncompressed formats. Transactions on the client side of the public key. Which bitcoin addresses should bitcoin wallets scan? The new client doesn't know which public key to use: either the bitcoin address generated with the compressed public key or the uncompressed public key, both are legitimate bitcoins addresses, both can be correctly signed by the private key, but they are completely different bitcoin addresses.
    To address this, newer Bitcoin clients will use a different Wallet Import
Format when private keys are exported from the wallet. The private key is suffixed with 01 to indicate that the private key is from a newer wallet and can only be used to generate compressed public keys. Private keys are uncompressed and cannot be compressed. "Compressed private key" actually just means "the private key used to generate the public key in compressed format", while "uncompressed private key" is used to mean "the private key used to generate the public key in uncompressed format" . To avoid further misunderstandings, it should only be possible to say that the export format is "WIF Compressed Format" or "WIF", not that the private key is "compressed".
    Note that these formats are not used interchangeably. In newer wallets that implement compressed public keys, private keys can only and always be exported in WIF compressed
format (prefixed with K or L). For older wallets that do not implement the public key in compressed format, the private key will only be exported in WIF format (prefixed with 5).
The purpose of this is to give a signal to the wallet that imports these private keys: whether to use the compressed public key and bitcoin address to scan the blockchain, or use the uncompressed
public key and bit coin address.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325992647&siteId=291194637