golang cryptography-1-theory

1. Learning Catalog

  1. Hash algorithm
  2. DES, 3DES, AES symmetric encryption
  3. RSA asymmetric encryption algorithm
  4. RSA digital signature algorithm
  5. Elliptic Curve Encryption Algorithm ECC
  6. Elliptic Curve Digital Signature Algorithm ECDSA
  7. Elliptic curve secp256k1 algorithm
  8. Encoding and decoding algorithm (base64, base58)
  9. Reference website

http://tools.jb51.net/code

http://www.fileformat.info/tool/hash.htm

2. Introduction to Cryptography Family

2.1 Classification

  • Irreversible hash algorithm
  • The encryption and decryption algorithm is reversible, but a key is required
  • The encoding and decoding algorithm is reversible and does not require a key

2.2 Hash algorithm (Message Digest)

MD4, MD5, Hash1, ripeMD160, SHA256 (Bitcoin), SHA3 (Ethereum), Keccak-256 (Ethereum)

2.3 Encryption and decryption algorithm

2.3.1 Symmetric encryption algorithm

DES, 3DES, AES, etc.

2.3.2 Asymmetric encryption algorithm

RSA, elliptic curve encryption algorithm

2.3.3 Digital signature algorithm

RSA digital signature algorithm, elliptic curve digital signature

2.4 Encoding and decoding algorithm

Base64, Base58 (blockchain)

Three, Hash algorithm

Hash (hash or become hash) algorithm can convert arbitrary length binary value (plain text) into (mapped to) shorter fixed-length binary value (Hash value)

Also known as: digital fingerprint, digital digest, message digest

3.1 Features

The characteristics that a good Hash algorithm should satisfy:

  • Forward fast: forward hash is fast
  • Reverse difficulty: It is difficult to reverse the plaintext in a limited time
  • Input sensitivity: avalanche effect, if the input changes a little, the hash result will change dramatically
  • Anti-collision and anti-collision
    • Conflict, collision: different plaintexts produce the same Hash
    • Anti-conflict: Try to make the output produced by different plaintexts different. Note that anti-conflict is not necessarily to avoid conflicts completely, but the cost of letting the attacker find two conflicting inputs is very large.

3.2 Typical

MD4, MD5, SHA-1 and SHA-2 series (SHA-224, SHA-256, SHA-384, SHA-512, the following number is the number of digits)

SHA = Secure Hash (安全Hash)

  • Both MD4/MD5 were designed by Ronald Rivest of Massachusetts Institute of Technology in 1990 and 1991. MD is the abbreviation of Message Digest. At present, MD5 has been proven to have no "strong collision resistance". It is compatible with the SHA-1 algorithm. All of them have been proven to be insufficiently safe to be used in business scenarios.

  • SHA (Secure Hash Algorithm) is a Hash function library

    • SHA-1 came out in 1995, the output is 160 bits, the principle is the same as MD4
    • In order to improve security, the SHA-2 series and SHA-1 have similar principles. SHA-224, SHA-256, SHA-384 and SHA-512 are called SHA-2
    • SHA-256 is the encryption algorithm used in the blockchain, the output is 256-bit binary, and the hexadecimal number is used to represent the 64-bit hexadecimal number
    • SHA-3, formerly known as Keccak algorithm, is an encryption hash algorithm. Keccak algorithm is the predecessor of SHA3. Ethereum first used Keccak algorithm, which was later standardized as SHA-3 algorithm.
      • Algorithms like Keccak-256 are still used in Ethereum
      • The output lengths of Keccak are: 512, 384, 256, 224
  • RIPEMD-160 (RACE's complete summary of original evaluation information)

    • It is a 160-bit encrypted Hash function, designed to replace 128-bit MD4 and MD5 ( do not want the length like SHA256, but still want to maintain security )
    • First developed in the framework of the EU project RIPE

3.3 Hash algorithm attack

Look for collision method, exhaustive method, password dictionary brute force cracking

  1. Find the collision method

    • There is currently no effective way to find collisions for MD5 and SHA1

    • Wang Xiaoyun cracked MD5 and realized the expected number of steps dropped from 280 to 269, which was a reduction of many orders of magnitude, but this is still an astronomical number.

  2. Exhaustive method and dictionary cracking

  3. Rainbow table attack

    Prevention of rainbow tables:

3.4 The difference between Hash and encryption and decryption

Simply put, Hash does not require a key, while encryption and decryption require a key. Hash is irreversible, while encryption and decryption are reversible

Choice of the two methods:

Need to know the original plaintext, then use encryption and decryption

You don't need to know the original plaintext, then use Hash

Fourth, symmetric encryption

Also known as private key encryption algorithm, single key encryption algorithm, traditional key encryption algorithm

The biggest feature of symmetric is that ** use the same key **

The biggest problem is the security of key sharing

4.1 DES and TripleDES (3DES) algorithms

The DES key is 64bit, corresponding to 8 bytes, of which 8bit is the parity bit, and the other 56 bits are the length of the password

The key of 3DES is three times that of DES, which is 192bit or 24 bytes

4.2 AES

4.2.1 Basic concepts

AES is an encryption standard, and the typical implementation is the Rijndael algorithm

AES can choose the length of the key, 128, 192, 256bit

4.2.2 Encryption mode

Five, asymmetric encryption

5.1 History

5.2 Basic concepts

Asymmetric: the encryption and decryption keys are different

Public key encryption, private key decryption: asymmetric encryption

Private key encryption, public key decryption: digital signature

Asymmetric encryption algorithms can be used as encryption and decryption algorithms as well as digital signature algorithms

5.3 The difference between symmetric and asymmetric

5.4 Elliptic Curve Encryption Algorithm

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-OQSufNZu-1608731503835)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\ image-20201223164907975.png)]

5.5 Digital signature

Only verify:

Plaintext encryption + verification

Six, character encoding/decoding

6.1 Base64

6.2 Base58

6.3 Base58Check

Verify that the Bitcoin address is correct

Guess you like

Origin blog.csdn.net/weixin_43988498/article/details/111600072