Encryption and Security: asymmetric encryption algorithm RSA 1024 public key, secret key, the length of plaintext and ciphertext

RSA 1024 refers to the public and private keys are 1024bit, i.e. 1024/8 = 128Bytes.

RSA principle

Select RSA algorithm key length is to balance security and application performance result, the longer the key length, the better the security, the longer the time required for encryption and decryption.

1, in 1024bit asymmetric encryption algorithm key equivalent to the intensity of the intensity 80bit symmetric encryption algorithm key;


 
2, the key length is increased to double, the time required for public key operations increased by about 4-fold, the time required for private key operations increased by about 8-fold, public and private key generation time increased by about 16 times;
 
3, the length of plaintext

Is proportional to the length of a plaintext can be encrypted with the key length:

len_in_byte (raw_data) = len_in_bit (key) / 8 -11, as 1024bit key, can encrypt a content length is 1024/8 -11 = 117 byte.

Therefore, asymmetric encryption is typically used to encrypt the symmetric key encryption algorithm, the encrypted content rather than directly.

Note:

Plaintext length less than or equal key length 128Bytes - 11 that is in itself not accurate, would create the encryption RSA 1024 only 117 byte length of the plaintext misunderstanding.

In fact, RSA encryption algorithm itself requires content that is expressly length m must satisfy 0 <m <n, this means that no more than a large integer n, otherwise an error.

So what if m = 0 is the result?

General RSA encryption will result directly return all 0, if m> n, calculating an error occurs.

Therefore, RSA encryption actual maximum length of the plaintext is 1024bits, but the question came:

If the length is less than this how to do?

On the need for padding, if there is no padding because the user can not determine the true length of the minutes after the decryption of the content, content issues such string is not large, as a terminator to 0, easy to distinguish.

However, binary data is difficult to understand, because of the uncertainty behind the 0 is the content or the content terminator.

As long as the use padding, it will take up actual plaintext length, padding standards we generally use are NoPPadding, OAEPPadding, PKCS1Padding and so on.

Where the PKCS padding # 1 recommended to take up 11 bytes, so only 117 bytes argument.

If this length is greater than how to do?

Many padding algorithm is often in the back, but the PKCS padding is in front, this is by design, the first byte deliberately set to 0 to ensure that the value of m is less than n.

Thus, 128 bytes (1024bits) - 11 bytes is exactly 117 bytes, but in terms of RSA encryption, padding is involved in encryption.

So, still in accordance with the actual plaintext RSA 1024 only 117 bytes.

About PKCS # 1 padding specification may refer to: RFC2313 chapter 8.1.

Before we send plaintext RSA encryption device, make sure the value is not greater than n, that is, if close to the n-bit long, so you need to re-padding segments encryption.

Unless we are "fixed length Quantitative own controllable understandable," the encryption is not required padding.

4, the length of the secret text

Encrypted cipher text of the key length, such as a key length of 1024b (128Byte), generates the final ciphertext fixed 1024b (128Byte)

Ciphertext is given qualified plaintext encryption bit length out of the result, this can be determined, the bit length of the bit length of the ciphertext encrypted with the key is the same, because the encryption formula:

C=(P^e)%n

Therefore, C is the maximum value of n-1, it can not exceed the number of bits n.

While n may be smaller than the number of bits, but the angle of transmission and storage, according to standard bit length is still carried out.

Thus, even if we encrypt a plaintext byte, out of the result of the operation should be used in accordance with the standard bit length.

 

refer:

https://blog.csdn.net/lvxiangan/article/details/45487943
http://blog.sina.com.cn/s/blog_4fcd1ea301012o4q.html
----------------
Disclaimer: this article is the original article CSDN bloggers "Jane commercial", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/liwei16611/article/details/83751851

Guess you like

Origin www.cnblogs.com/colder/p/12370175.html