estoy haciendo cifrado y descifrado usando un algoritmo AES Algoritmo con castillo hinchableJ2ME AES descifrado error (org.bouncycastle.crypto.InvalidCipherTextException: bloque de almohadilla corrompido)
Mi cifrado y descifrado funciona bien, pero me da error cuando mi llanura tamaño de la letra es más grande
incluso a veces se está dando datos que no son descifrados
public static boolean setEncryptionKey(String keyText)
{
byte[] keyBytes = keyText.getBytes();
key = new KeyParameter(keyBytes);
engine = new AESFastEngine();
cipher = new PaddedBufferedBlockCipher(engine);
return true;
}
cifrado:
public static String encryptString(String plainText)
{
byte[] plainArray = plainText.getBytes();
cipher.init(true, key);
byte[] cipherBytes = new byte[cipher.getOutputSize(plainArray.length)];
int cipherLength = cipher.processBytes(plainArray, 0, plainArray.length, cipherBytes, 0);
cipher.doFinal(cipherBytes, cipherLength);
String cipherString = new String(cipherBytes);
return cipherString;
}
Descifrado:
public static String decryptString(String encryptedText)
{
byte[] cipherBytes = encryptedText.getBytes();
cipher.init(false, key);
byte[] decryptedBytes = new byte[cipher.getOutputSize(cipherBytes.length)];
int decryptedLength = cipher.processBytes(cipherBytes, 0, cipherBytes.length, decryptedBytes, 0);
cipher.doFinal(decryptedBytes, decryptedLength);
String decryptedString = new String(decryptedBytes);
int index = decryptedString.indexOf("\u0000");
if (index >= 0)
{
decryptedString = decryptedString.substring(0, index);
}
return decryptedString;
}
Este descifrado me está dando siguiente error
org.bouncycastle.crypto.InvalidCipherTextException: pad block corrupted
at org.bouncycastle.crypto.paddings.PKCS7Padding.padCount(+30)
at org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher.doFinal(+190)
at com.NewCrypto.decryptString(NewCrypto.java:103)
at com.New_Midlet.startApp(New_Midlet.java:23)
at javax.microedition.midlet.MIDletProxy.startApp(MIDletProxy.java:44)
at com.sun.midp.midlet.Scheduler.schedule(Scheduler.java:375)
at com.sun.midp.main.Main.runLocalClass(Main.java:477)
at com.sun.midp.main.Main.main(+80)
lo que podría ser el problema?
Cualquier codificador de base64 que aún genere bytes en lugar de caracteres es un poco estúpido en mi opinión. Ya puedo ver el horror cuando alguien intenta transmitirlo a un archivo XML UTF-16. Además, no parece ser compatible con ninguna otra forma de base64 que no sea la predeterminada. Mmm, tal vez debería hacer que mi codificador esté disponible también. –
@owlstead: estoy de acuerdo. El códec Harder emitirá cadenas de caracteres y admitirá el estúpido estilo de Apache commons. –