Reputation: 101
I am trying to find a public key encryption method in java which will produce a string with the the same length as the original one. The usual rsa doesn't work. It produces a very long string for 3 character strings. What I want to do for my project is encrypt a string with a key then encrypt it again with a key but having a long string just slows down the process immensely. Any suggestions?
Upvotes: 0
Views: 615
Reputation: 61892
RSA doesn't have a streaming cipher mode which could create ciphertexts of the same length as the plaintexts. The ciphertext will always be the size of the modulus. So if you're using RSA 2048, the ciphertext will be 256 bytes long. There is no way to make it shorter. This will be exactly your requirement of 256 bytes, but if you also need to encode it for persistence of transmission then it will be bigger.
You could use a shorter RSA keys such as RSA 1536 which will result in 192 bytes ciphertext and if you would encode it with Base 64 it will be exactly 256 bytes long.
Upvotes: 2