Share several common encryption algorithms in Java (four)

Symmetric encryption algorithm is an earlier encryption algorithm with mature technology. In the symmetric encryption algorithm, The data sender will clear text (original data) and encryption key (MI Yue) after being processed by a special encryption algorithm, it becomes a complex encrypted ciphertext and is sent out. After receiving the ciphertext, if the recipient wants to interpret the original text, it needs to decrypt the ciphertext with the encryption key and the inverse algorithm of the same algorithm to restore it to readable plaintext. In the symmetric encryption algorithm, only one key is used, and both the sender and the recipient agree Using this key to encrypt and decrypt data requires the decryptor to know the encryption key in advance.

Simple java encryption algorithms include:

Strictly speaking, base belongs to the coding format, rather than the encryption algorithm MD (message digest algorithm), Sha (secure hash algorithm) HMAC (hash message authentication code)

The first BASE

Base is one of the most common encoding methods used to transmit bit byte codes on the network. You can check RFC ~ RFC, which has the detailed specification of mime. Base encoding can be used to transfer long identification information in HTTP environment. For example, in the Java persistence system hibernate, Base is used to encode a long unique identifier (generally - bit UUID) into a string, which is used as a parameter in HTTP forms and HTTP get URLs. In other applications, it is often necessary to encode binary data into a suitable URL (including hidden form fields). At this time, base coding is unreadable, that is, the encoded data will not be directly seen by human eyes. (source: Baidu Encyclopedia)

Java implementation code:

The second MD

MD, namely message digest algorithm, is used to ensure the integrity and consistency of information transmission. It is one of the hash algorithms widely used by computers (also translated into digest algorithm and hash algorithm). MD has been widely implemented in mainstream programming languages. Data (such as Chinese characters) operation is another fixed length value, which is the basic principle of hash algorithm. The predecessor of MD is MD, MD and MD. it is widely used in encryption and decryption technology and is often used for file verification. Verification? No matter how large the file is, it can generate a unique MD value after MD. for example, ISO verification is MD verification. How to use it? Of course, it generates MD value after ISO passes MD. generally Linux ISO friends have seen the MD string next to the download link. It is used to verify whether the files are consistent.

Java implementation:

MD algorithm has the following characteristics:

Compressibility: for any length of data, the calculated MD value length is fixed Easy to calculate: it is easy to calculate the MD value from the original data Modification resistance: the MD value obtained by any modification to the original data, even if only one byte is modified, is very different Weak anti-collision: given the original data and its MD value, it is very difficult to find a data with the same MD value (i.e. forged data). Strong anti-collision: it is very difficult to find two different data so that they have the same MD value.

The function of MD is to make large capacity information "compressed" into a confidential format (that is, to transform a byte string of any length into a hexadecimal digit string of a certain length) before signing a private key with digital signature software. In addition to MD, the more famous ones are Sha -, ripemd and Haval.

The third SHA

Secure hash algorithm is mainly applicable to the digital signature algorithm defined in digital signature standard (DSS) (digital signature algorithm DSA). For messages with a length less than ^ bits, Sha will generate a bit message summary. After years of development and improvement by encryption experts, the algorithm has been increasingly improved and widely used. The idea of the algorithm is to receive a piece of plaintext and then convert it into a piece of plaintext in an irreversible way (usually smaller) ciphertext can also be simply understood as the process of taking a string of input codes (called pre mapping or information) and transforming them into an output sequence with short length and fixed bits, that is, hash value (also known as information digest or information authentication code). Hash function value can be said to be a "fingerprint" or "digest" of plaintext Therefore, the digital signature of hash value can be regarded as the digital signature of this plaintext.

Java implementation:

Sha - comparison with MD

Because both are derived from MD, Sha - and MD are very similar to each other. Accordingly, their strength and other characteristics are similar, but there are the following differences:

Security against forced attacks: the most significant and important difference is that Sha summaries are bit longer than MD summaries. Using forced technology, the difficulty of generating any message so that its summary is equal to the given message summary is an operation of ^ order of magnitude for MD and ^ order of magnitude for Sha -. In this way, Sha - has greater strength against forced attacks.

Security of Cryptanalysis: due to the design of MD, Sha - is vulnerable to cryptanalysis attacks.

Speed: on the same hardware, Sha - runs slower than MD.

The fourth HMAC

HMAC (hash message authentication code, hash message authentication code, authentication protocol of hash algorithm based on key. The principle of message authentication code is to use public function and key to generate a value of fixed length as authentication identification, and use this identification to identify the integrity of message. A key is used to generate a small data block of fixed size, namely Mac, and add it to The message is then transmitted. The receiver uses the key shared with the sender for authentication, etc.

Java implementation code:

The above contents are several common encryption algorithms (four) in Java shared by Xiaobian. I hope you like them.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>