javax.crypto.IllegalBlockSizeException
javax.crypto.IllegalBlockSizeException: Data must not be longer than 53 bytes i know that it is because of the RSA algorithm can only encrypt data that has a maximum byte length of the RSA key length in bits di开发者_如何学Pythonvided with eight minus eleven padding bytes, i.e. number of maximum bytes = key length in bits / 8 - 11.
Here am using a 512 key size so it is not allowing more than 53.but i need to maintain 512 bit key but to encrypt more than 53 byte is there any possibility .
Yes and no. You can't encrypt with RSA, but you can go with one of the following:
Do the usual approach of encrypting with symmetric algorithm and passing the key encrypted with RSA. For example, to send data D to another man with public key PK:
- send Ek(D) (D encrypted with symmetric algorithm with key K)
- send Epk(K) as well (K encrypted with RSA algorithm with PK)
The other side open PK(K) to get K, and open K(D) to get D.
split the data into small pieces and encrypt each one separately.
The first approach is a much better one for two main reasons:
- You don't mess with the data (except of the encryption itself).
- Symmetric encryption / decryption is much faster than public encryption, for example, RC4 is a simple XOR of the data, while RSA uses a large power.
(3. There must be a reason why PGP is so common...)
Why don't you employ enveloping? Generate a symmetric key (AES), encrypt your data with that AES key, then encrypted the AES key with a public RSA key. Send the encrypted data, along with the encrypted AES Key. Then decrypt the AES key with the private RSA key, and use that to decrypt the rest of the data. This will allow you to encrypt data of any size.
精彩评论