Current location - Quotes Website - Personality signature - Some common encryption in Android ((symmetric encryption DES, AES), asymmetric encryption (RSA), MD5).
Some common encryption in Android ((symmetric encryption DES, AES), asymmetric encryption (RSA), MD5).
DES is a symmetric encryption algorithm. The so-called symmetric encryption algorithm is an algorithm that uses the same key for encryption and decryption. DES encryption algorithm comes from the research of IBM,

Later, it was officially adopted by the US government, and then it began to spread widely, but it was used less and less in recent years, because DES used a 56-bit key and had modern computing power.

It can be cracked in 24 hours.

Call process

Recently, I made a WeChat applet to obtain the decryption of the mobile phone number information bound by the user, and tried many methods. Although it was not completely solved in the end, it reached my limit. Sometimes you get an error: javax.crypto.badpaddingexception: padblock corrupted.

A detailed description of the error.

Every time you just log in to the applet to get the mobile phone number, there will be a problem that the first decryption fails and you will succeed if you try again. If you log out and log in continuously, there is no problem of leaking secrets again. However, if you temporarily stop the operation and log in after logging out, there will be a problem that you failed to reveal the secret the first time, and you will succeed if you try again.

I have ruled out the points on the internet and official documents. The encrypted ciphertext is obtained by calling the wx.login () method in the front end and calling the WeChat authorization interface in my back end, and then obtaining the user's sessionkey and openId. Then the front-end calls the user's mobile phone number interface to obtain sessionkey encryption, so that I can ensure that sessionkey is up-to-date every time. Will not expire.

And I found through the log that the first time it failed, the second time it was decrypted successfully under the condition that the sessionkey remained unchanged.

Encryption algorithm, RSA is an unavoidable topic, because RSA algorithm is the most popular public key algorithm at present, which can be used for encryption and digital signature of users. Not only in the field of cryptocurrency, but also in the field of traditional Internet. It has been put forward for more than 20 years and has experienced various tests. It is generally considered as one of the best public key schemes at present.

The characteristic of asymmetric encryption algorithm is that the encryption key is different from the decryption key. Keys are divided into public keys and private keys, and plaintext encrypted with private keys can only be decrypted with public keys. Plaintext encrypted with public key can only be decrypted with private key.

1. What is "prime number"?

A prime number is an integer that can be expressed as the product of itself and 1, and cannot be expressed as the product of any two other integers.

Second, what is a "prime number" (or "prime number")?

The definition of prime number in primary school mathematics textbooks is as follows: "The common divisor is only 1 two numbers, which is called prime number.

(1) Two prime numbers must be prime numbers. Such as 2 and 7, 13 and 19.

(2) If a prime number is not divisible by another composite number, these two numbers are prime numbers. For example, 3 and 10, 5 and 26.

(3) 1 is neither a prime number nor a composite number, but a prime number of any natural number. Such as 1 and 9908.

(4) Two adjacent natural numbers are prime numbers. For example, 15, 16.

(5) Two adjacent odd numbers are prime numbers. Such as 49 and 5 1.

(6) A large number is a prime number and two numbers are prime numbers. Such as 97 and 88.

(7) Decimals are prime numbers, and numbers whose two large numbers are not multiples of decimals are coprime numbers. Such as 7 and 16.

(8) Both numbers are composite numbers (there is a big difference between them), and all prime factors of decimals are not divisors of large numbers. These two numbers are prime numbers. For example, 357 and 7 15,357 = 3× 7× 17, while 3,7 and17 are not divisors of 715, and both numbers are prime numbers. Wait a minute.

3. What is modular exponential operation?

Exponential operation is well known. Needless to say, let's talk about modular operation first. Modular operation is integer operation, with integer m and modular operation with n, that is, m mod n, how to do it? Let m be divisible by n and only take the remainder as the result. This is called modular operation. For example,10mod3 =1; 26 mod 6 = 2; 28 mod 2 =0 and so on.

Modular exponential operation is to do exponential operation first, and then take the result to do modular operation. For example, (5 3) mod7 = (125mod7) = 6.

Among them, the symbol represents the mathematical exponential operation; Mod stands for modular operation, that is, division takes the remainder. The specific algorithm steps are as follows:

(1) Choose a pair of different prime numbers p and q that are large enough.

(2) calculate n = p q.

(3) calculate f(n)=(p- 1) (q- 1), and keep p and q strictly confidential, so as not to let anyone know.

(4) Find a number e that is coprime with f(n) as the public key index, 1

(5) Calculate the private key index d so that d satisfies (d*e) mod f(n) = 1.

(6) public key KU=(e, n) and private key KR=(d, n).

(7) When encrypting, the plaintext is first converted into an integer m from 0 to n- 1. If the plaintext is long, it can be divided into appropriate groups and then exchanged. If the ciphertext is c, the encryption process is: c = m e mod n.

(8) The decryption process is: m = c d mod n.

In the application of RSA cryptography, the public key KU is public, that is, the values of e and n can be obtained by third-party eavesdroppers. The problem of cracking RSA cipher is to find the value of d from the known values of e and n (n equals pq), so as to get the private key to crack the ciphertext. It can be seen from the above formula: (d e) mod ((P- 1) (Q- 1)) =1,and the essential problem of password cracking is to find (p-1) and (q-1) from the numerical value of p Q.

When P and Q are big prime numbers, it is a recognized mathematical problem to decompose the factors P and Q from their product p q. For example, when p*q is as big as 1024, no one has been able to complete the task of factorization with any calculation tools. Therefore, RSA has been put forward for nearly 20 years, and it has been tested by various attacks and gradually accepted by people. It is generally considered as one of the best public key schemes at present.

Disadvantages 1: Although the security of RSA depends on the factorization of large numbers, it is not proved theoretically that the difficulty of deciphering RSA is equal to the difficulty of factorization of large numbers. That is, one of RSA's major defects is that it can't grasp its confidentiality in theory.

Many times in Android development. In order to ensure the security of user accounts, MD5 encryption algorithm is usually used when saving user passwords. The algorithm is irreversible and has certain security.

MD5 is not an encryption algorithm, because if the purpose is encryption, one condition that must be met is that it can be decrypted after encryption. But MD5 can't recover the original data from the results.

MD5 is just a hash algorithm.