I encrypt my message with a symmetric key and the symmetric key itself has to be further encrypted with different RSA public keys. When I tried to implement the above I got the following error:
javax.crypto.IllegalBlockSizeException: The input was invalid: Invalid input length.
at com.rsa.shareCrypto.j.hD.engineDoFinal(Unknown Source)
at javax.crypto.Cipher.doFinal(Cipher.java:2087)
at wrap1.main(wrap1.java:69)
Is there a way to solve this problem ?
i need to do something like this [[[[key]PK-A]PK-B]PK-C], where PK-A = Public key of A, similarly PK-B and PK-C.
Below are the codes that i tried here are the codes
String InitialKey = "2011BCSChampionA";
byte[] initkey = InitialKey.getBytes();
// First level encryption of the key
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(1024);
KeyPair keypair = keyGen.genKeyPair();
PrivateKey privateKey = keypair.getPrivate();
PublicKey publicKey = keypair.getPublic();
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] cipherData = cipher.doFinal(initkey);
// Second level of encryption
KeyPairGenerator keyGen1 = KeyPairGenerator.getInstance("RSA");
keyGen1.initialize(1024);
KeyPair keypair1 = keyGen1.genKeyPair();
PrivateKey prvKey = keypair1.getPrivate();
PublicKey pubKey = keypair1.getPublic();
Cipher cipher1 = Cipher.getInstance("RSA");
cipher1.init(Cipher.ENCRYPT_MODE, pubKey);
byte[] cipherData_new = cipher1.doFinal(cipherData);
Is there a way to solve this problem ?If you post your code too, most definitely yes!