Current location - Quotes Website - Personality signature - How iOS uses modulus and exponent for RSA encryption
How iOS uses modulus and exponent for RSA encryption
First, confirm the size of the data you want to encrypt. If it is large, it is suggested to encrypt with symmetric algorithm first, and encrypt the key of symmetric algorithm with RSA.

Now define:

You get a public key modulus of n and an exponent of e.

The bit length of n is len(N)

The number of bytes occupied by n is k = (len(N)+7)/8.

The data to be encrypted is D (either your original data or the symmetric algorithm key).

If your encrypted data is small, you can also encrypt it directly with RSA. Relatively small means that the length of encrypted data must meet the filling condition. If PKCS 1_ 1.5 is adopted, the number of bytes occupied by d should be less than k- 1 1.

The operation process is simple: fill d into D 1, and require that the number of bytes occupied by D 1 is k (that is, the same length as n).

Then the process of calculating ciphertext e is de = (d 1 e)% n (for exponential operation).

I suggest you use some ready-made libraries to implement in the program. If you have OpenSSL, you can search online, and there should be a lot of information.

If not, you can directly introduce some libraries for calculating large numbers and directly perform modular operations (don't separate them, it's too slow).