What is RSA encryption output size when using 2048 bit key and pkcs1padding.
Is it always 256 bytes independent of input size?
How can i calculate it for other key sizes?
the modulus size defines the key size. So the output of an RSA encryption is the same as the key size: ceil(keySize / 8.0) using floats or (keySize + 8 - 1) / 8 using integers. RSA with OAEP padding uses the same technique, so the answer is correct for OAEP as well (and most other, less known schemes such as RSA-KEM).
The modulus size is the key size in bits / 8. Thus a 1024-bit RSA key using OAEP padding can encrypt up to (1024/8) – 42 = 128 – 42 = 86 bytes. A 2048-bit key can encrypt up to (2048/8) – 42 = 256 – 42 = 214 bytes.
Symmetric encryption does not increase the size of the data. The maximum asymmetric data size is 11 bytes less than the size of the key.
The security of RSA depends on how large n is, which is often measured in the number of bits for n. Current recommendation is 1024 bits for n. p and q should have the same bit length, so for 1024 bits RSA, p and q should be about 512 bits.
5 Answers 5. RSA, as defined by PKCS#1, encrypts "messages" of limited size. With the commonly used "v1.5 padding" and a 2048-bit RSA key, the maximum size of data which can be encrypted with RSA is 245 bytes.
The output-size should always equals the size of the Modulus (part of the key), so: 2048 bit Modulus -> 2048 bit output 1024 bit Modulus -> 1024 bit output ... If it is not, there exist numerous attacks on RSA, see here for basic information about that.
RSA (Rivest–Shamir–Adleman) is one of the first public-key cryptosystems and is widely used for secure data transmission. In such a cryptosystem, the encryption key is public and it is different from the decryption key which is kept secret (private).
The exact difference is implementation dependent, but may be on the order of 100 to 1000 times faster. It is widely known that AES encrypts a 16-byte block of data at a time. However, how much data can be encrypted at one time with an RSA key is usually only discussed in vague terms such as “use RSA to encrypt session keys.”
Yes, it is.
The output-size should always equals the size of the Modulus
(part of the key), so:
2048 bit Modulus -> 2048 bit output
1024 bit Modulus -> 1024 bit output
...
If it is not, there exist numerous attacks on RSA, see here for basic information about that.
So to guarantee that the output is 2048 bit
even when the input to encrypt is, let's say 7
,
a padding must always be applied!
The output (as integer) of RSAEP (RSA encryption primitive) is always between 0 and n:
If the message representative m is not between 0 and n-1, output message representative out of range and stop.
Let c = m^e mod n.
Output c.
Of course, c
is a number. So you have to convert it to bytes for it to be usable. The only thing known about c
is that it is smaller than n
for a large value of m
. It may be that c
is a few bytes smaller even if m
is large.
You've mentioned PKCS1Padding, which is part of the RSAES-PKCS1-V1_5-ENCRYPT encryption scheme. The padding will make sure that m
is always large and randomized; requirements for RSA encryption to be secure.
You'll find that the encoding of c
is specified in there:
...
Step 4: Convert the ciphertext representative c to a ciphertext C of length k octets: C = I2OSP (c, k)
...
where k is the size of the modulus in octets (bytes).
So yes, the answer is always k
, the size of the modulus in bytes. Simply because the standard requires it that way. It is a value encoded as unsigned big endian number prefixed with as many zero bytes as required.
Notes:
the modulus size defines the key size. So the output of an RSA encryption is the same as the key size: ceil(keySize / 8.0)
using floats or (keySize + 8 - 1) / 8
using integers.
RSA with OAEP padding uses the same technique, so the answer is correct for OAEP as well (and most other, less known schemes such as RSA-KEM).
Many library routines that perform "raw" RSA (just modular exponentiation of the message with the public exponent) still perform the I2OSP function - but better check to make sure.
The output size of plain RSA (using some padding scheme, but no hybrid encryption) is always the key size. The reason is that for some public key n
the result is some integer c
with 0<=c<n
. There are lots of introductions for RSA, e.g. http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-045j-automata-computability-and-complexity-spring-2011/lecture-notes/MIT6_045JS11_rsa.pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With