Share several encryption algorithms commonly used in Java (four types)
Symmetric encryption algorithm is an earlier encryption algorithm with mature technology. In the symmetric encryption algorithm, the data sender processes the plaintext (original data) and encryption key (mi yue) together with a special encryption algorithm, turning them into complex encrypted ciphertext and sending them out. After the recipient receives the ciphertext, if he wants to decipher the original text, he needs to use the key used for encryption and the inverse algorithm of the same algorithm to decrypt the ciphertext in order to restore it to readable plaintext. In the symmetric encryption algorithm, only one key is used. Both the sender and the receiver use this key to encrypt and decrypt the data. This requires the decryptor to know the encryption key in advance.
Simple java encryption algorithms are:
BASE Strictly speaking, it is an encoding format, not an encryption algorithm
MD (Message Digest algorithm, message digest algorithm)
SHA( Secure Hash Algorithm, secure hash algorithm)
HMAC (Hash Message Authentication Code, hash message authentication code)
The first one. BASE
Base is the most popular one on the network One of the common encoding methods used to transmit Bit byte code, you can check RFC~RFC, which has detailed specifications of MIME. Base encoding can be used to convey longer identification information in an HTTP environment. For example, in the Java Persistence system Hibernate, Base is used to encode a long unique identifier (usually a -bit UUID) into a string, which is used as parameters in HTTP forms and HTTP GET URLs. In other applications, it is often necessary to encode binary data into a form suitable for placement in a URL (including hidden form fields). At this time, Base encoding is unreadable, that is, the encoded data will not be directly visible to the naked eye. (Source Baidu Encyclopedia)
java implementation code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
The second type. MD
MD is Message-Digest Algorithm (information-digest algorithm), used to ensure complete and consistent information transmission. It is one of the hash algorithms widely used in computers (also translated as digest algorithm and hash algorithm). MD has been generally implemented in mainstream programming languages. Computing data (such as Chinese characters) into another fixed-length value is the basic principle of the hash algorithm. The predecessors of MD are MD, MD and MD. Widely used in encryption and decryption technology, often used for file verification. check? No matter how big the file is, a unique MD value can be generated after MD. For example, the current ISO calibration is MD calibration. how to use? Of course, the MD value is generated after ISO is passed through MD. Generally, friends who have downloaded linux-ISO have seen the MD string next to the download link. It is used to verify whether the files are consistent.
Java implementation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
MD algorithm has the following characteristics:
, Compressibility: data of any length can be calculated The MD value lengths are all fixed.
. Easy to calculate: It is easy to calculate the MD value from the original data.
. Anti-modification: If any changes are made to the original data, even if only a single byte is modified, the resulting MD value will be very different.
, Weak anti-collision: Knowing the original data and its MD value, it is very difficult to find data with the same MD value (ie, 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 allow large-capacity information to be "compressed" into a confidential format before signing the private key with digital signature software (that is, converting a byte string of any length into a certain length of sixteen hexadecimal digit string). In addition to MD, the more famous ones include sha-, RIPEMD and Haval.
The third type.SHA
Secure Hash Algorithm is mainly applicable to the Digital Signature Algorithm DSA defined in the Digital Signature Standard DSS. . For messages less than ^ bits in length, SHA produces a one-bit message digest. This algorithm has been developed and improved by encryption experts over the years and has been increasingly perfected and widely used. The idea of this algorithm is to receive a piece of plaintext and then convert it into a piece of (usually smaller) ciphertext in an irreversible way. It can also be simply understood as taking a string of input codes (called pre-mapping or information), and The process of converting them into a short-length, fixed-digit output sequence, that is, a hash value (also called a message digest or message authentication code). The hash function value can be said to be a "fingerprint" or "digest" of the plaintext, so the digital signature of the hash value can be regarded as the digital signature of the plaintext.
java implementation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
Comparison between SHA- and MD
Because both are exported by MD, SHA- and MD are very similar to each other. Correspondingly, their strengths and other characteristics are similar, but there are the following differences:
Security against brute force attacks: The most significant and important difference is that the SHA-digest is longer than the MD digest. Using brute force techniques, the difficulty of generating any message whose digest is equal to a given message digest is an operation of the order of magnitude for MD, and an operation of the order of magnitude for SHA-. This way, SHA- has greater strength against brute force attacks.
Security against cryptanalysis: Due to the design of MD, it is vulnerable to cryptanalysis attacks, while SHA- appears to be less vulnerable to such attacks.
Speed: SHA- runs slower than MD on the same hardware.
The fourth type.HMAC
HMAC(Hash Message Authentication Code,散列消息鉴别码,基于密钥的Hash算法的认证协议。消息鉴别码实现鉴别的原理是,用公开函数和密钥产生一个固定长度的值作为认证标识,用这个标识鉴别消息的完整性。使用一个密钥生成一个固定大小的小数据块,即MAC,并将其加入到消息中,然后传输。接收方利用与发送方共享的密钥进行鉴别认证等。
java实现代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
以上内容是小编给大家分享的Java常用几种加密算法(四种),希望大家喜欢。
更多分享Java常用几种加密算法(四种)相关文章请关注PHP中文网!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

Field mapping processing in system docking often encounters a difficult problem when performing system docking: how to effectively map the interface fields of system A...

Start Spring using IntelliJIDEAUltimate version...

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

When using TKMyBatis for database queries, how to gracefully get entity class variable names to build query conditions is a common problem. This article will pin...

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...
