He cifrado una cadena: "EJEMPLO" en Oracle JDK 1.7 utilizando el siguiente código
//ENCRYPTION of "EXAMPLE"
byte[] clearText = {69, 88, 65, 77, 80, 76, 69};
KeyPair keyPair = EncodingTest.loadRSAKeyPair();
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPwithSHA-256andMGF1Padding");
cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPublic());
byte[] encrypted = cipher.doFinal(clearText);
byte[] encoded = org.apache.commons.codec.binary.Base64.encodeBase64(encryptedAES);
Luego decodifico y desencripto la cadena codificada creada anteriormente en una plataforma IBM JDK 1.7 utilizando el siguiente código
//DECRYPTION
byte[] encoded={83,74,97,99,110,79,84,97,76,85,106,79,120,88,83,70,110,104,86,55,48,70,57,121,57,72,102,116,54,70,49,68,71,112,97,97,110,72,87,107,119,86,72,47,122,47,114,100,84,79,115,88,101,117,109,122,83,50,99,115,114,76,54,102,118,100,116,82,79,68,80,83,70,107,119,90,101,89,106,88,122,117,69,109,49,77,113,51,120,104,116,68,99,120,114,82,118,82,99,50,120,78,74,43,121,55,53,88,67,75,50,85,88,118,88,78,74,43,49,121,55,76,87,116,110,51,105,79,77,119,107,88,68,53,78,51,54,111,110,50,69,49,99,102,57,57,55,48,119,52,107,81,116,116,111,77,74,69,112,48,111,82,112,100,99,113,104,101,47,89,79,98,69,78,49,49,57,77,77,79,109,52,106,66,54,113,86,82,53,121,119,43,101,65,77,104,107,104,75,82,85,87,80,121,97,111,84,66,112,104,83,103,51,114,110,98,115,120,67,109,48,105,69,77,100,106,72,118,118,102,103,103,75,105,79,109,76,50,86,77,116,106,82,52,43,122,108,69,48,120,52,89,75,118,109,115,116,78,54,53,100,85,51,100,83,102,53,57,113,43,103,53,106,121,50,97,78,72,115,68,67,69,105,71,82,80,80,103,69,72,113,47,97,109,50,111,108,88,119,78,116,52,114,99,110,48,90,79,108,55,49,67,74,88,89,107,79,102,110,102,51,103,78,65,108,81,73,56,105,120,97,66,65,99,109,80,76,77,54,72,81,103,61,61,};
byte[] encrypted = org.apache.commons.codec.binary.Base64.decodeBase64(encoded);
Cipher decrCipher = Cipher.getInstance("RSA/ECB/OAEPwithSHA-256andMGF1Padding");
decrCipher.init(Cipher.DECRYPT_MODE, keyPair.getPrivate());
byte[] decryptedAES = decrCipher.doFinal(encrypted);
Esto falla con una excepción de relleno incorrecto en la última línea de código. Sin embargo, el mismo código de descifrado funciona en el JDK de Oracle.
¿Pensé que las transformaciones se implementarían de la misma manera en JVMS? ¿Me estoy perdiendo algo? ¿Podría alguien ayudarme?
Gracias, Ranjit