1 Unidirectional hash encryption

Unidirectional hash encryption refers to the process of hashing information of different input lengths to obtain the output of fixed length. The hashing process is unidirectional and irreversible. Common one-way hashing algorithms include MD5 and SHA.

For example, on a website, the user password can be encrypted by MD5 and saved. When a user logs in, the password is encrypted and compared with the ciphertext in the database. If the password is the same, the authentication succeeds.

To enhance the security of the calculation, the data can be added with a key to increase the difficulty of pojie.

It is recommended to use Commons -codec jars such as Commons -codec-1.8.jar.

?

12 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 /** * STRING MD5 encryption * @param STR * @return/ public static String encryptMD5(String str) { return DigestUtils.md5Hex(str); } /* * Encrypt the string SHA * @param STR * @return */public static String encryptSHA(String str) { return DigestUtils.sha1Hex(str); }

2 Symmetric encryption

Symmetric encryption is when encryption and decryption use the same key. Plaintext can be encrypted according to the key, and ciphertext can be decrypted according to the key.

Symmetric encryption algorithm is often used in Cookie encryption, communication encryption and other occasions. Common algorithms include DES, RC, AES, etc.

Symmetric algorithm has the advantages of simple algorithm, high encryption and decryption efficiency, low system overhead and suitable for massive data encryption. Is a traditional encryption method, is also the most commonly used encryption method, suitable for most of the occasions that need encryption.

Java – DES encryption/decryption – demo: www.oschina.net/code/snippe…

3 Asymmetric encryption

Asymmetric encryption means that different keys are used for encryption and decryption. One is public key, and the other is private key. The information encrypted with the public key must be unlocked with the private key, and the information encrypted with the private key can be unlocked only with the public key.

Asymmetric encryption technology is often used in information security transmission, digital signature and other occasions. Common algorithms include RSA algorithm.

For example, the sender obtains the recipient’s public key, encrypts the submitted information, and sends the ciphertext to the recipient over an insecure transmission channel. After obtaining the key, the recipient decrypts the encrypted information using its own private key. When information is stolen during transmission, the thief cannot obtain plaintext without the key.

On the contrary, the signer encrypts the information with his private key and sends it to the receiver, who decrypts the information with the signer’s public key. Since the private key is only owned by the signer, the sent information is signed and cannot be repudiated.

Java – RSA encryption/decryption – demo: blog.csdn.net/centralperk…

Blog.csdn.net/liuhuabai10…

4 summarizes

In practical application, it can be mixed according to the actual needs. At the same time, the key is very important in encryption technology. Once the key is out, the encrypted information loses its secrecy. In some projects with high security, keys and algorithms can be deployed independently to provide external encryption and decryption services and are maintained by special personnel, resulting in high system performance overhead. Or the encryption algorithm is put in the application, the key is deployed separately and updated regularly, and the key can be sliced and stored on multiple servers. Each server is managed by special personnel, and everyone performs their own duties, so that no one can view and complete the key information.

Literature: “Technical Architecture of Large Website” — Li Zhihui (this book is really a good book, can greatly broaden the horizons of programmers)