What are encryption and signing

RSA
MD5
DES
AES



A
B
A
B
B
C
C
A


Which scenarios are used

In the payment field where security is the most important, encryption and signature are often used to ensure data security. Because RAS encryption is hard to crack, it is often used to secure data. RAS, also known as asymmetric encryption, has a public key that can be handed to each other and a private key that can be kept. The public key is used for encryption, while the private key is used for signing. First, the merchant generates a pair of public and private keys, which are handed to the bank. The bank also gives the generated public key to the merchant. When a merchant sends a payment message to the bank, it first uses its private key to sign the parameters required for payment to generate the field sign, and then encrypts the value of the field sign and previous parameters with the public key of the bank, and then sends them to the bank through some transmission protocols. The bank decrypts the message with its own private key. If the message cannot be decrypted, it is proved that it was not sent by the merchant. If the decryption succeeds, the public key of the merchant is used to unsign the sign and compare with the data for judgment.

why

Why not use Des, Aes or Md5?

Des Symmetric encryption requires a key. These keys can be brute force cracked under certain conditions, as can MD5.

Why not use public key signature and private key encryption?

Suppose the private key is used for encryption and the public key is signed. So in the process of the merchant to the bank, the bank needs to decrypt the data with the public key. Since the public key is exposed outside, if the non-bank person gets it, the data can be seen after decryption, although he is not sure whether the data has been modified. With a public key, the private key is in the hands of the bank.

What needs attention

  1. Md5 is not only used for encryption, but also for signing.
  2. RAS, while safe, can be difficult to develop.

How to use

The signature of the

       Map<String,String> map=new HashMap<>();
        map.put("client_id", AppConstant.APPID);
        map.put("method"."user.baseinfo");
        map.put("access_token",accessToken);
        map.put("timestamp",String.valueOf(System.currentTimeMillis()));
        map.put("client_secret",AppConstant.APPSECRET);
        String sign= MD5.md5Sign(map);
        map.put("sign",sign); Public static String md5Sign(Map<String,String> params){String[] keys = params.keySet().toarray (new) String[0]); Arrays.sort(keys); StringBuilder query = new StringBuilder();for(String key : keys) { String value = params.get(key); query.append(key).append(value); } // Step 3: MD5 encryptionreturn DigestUtils.md5Hex(query.toString());
    }
Copy the code

This code is signed in MD5 mode. It can be seen here that signing is only an application of encryption, so any encryption mode can be used as a signature.

conclusion

Attached answer: the little fire dragon was abandoned by the trainer. Just the theatrical version: a scene from “It’s Gonna be You.” Poke me, link me. Do not know if you have seen, or very good-looking, I big skin god spoke!!