Estoy haciendo una tarea sobre el uso de blowfish para hacer cifrado & descifrado en Java.Cómo solucionar javax.crypto.IllegalBlockSizeException: datos no bloqueados tamaño
He añadido un proveedor y obtengo la instancia "Blowfish/ECB/NoPadding", pero sigo teniendo este error cuando realizo el cifrado.
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
ej .:
public static byte[] encrypt(byte to_encrypt[], byte strkey[]) {
try {
SecretKeySpec key = new SecretKeySpec(strkey, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish/ECB/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, key);
return cipher.doFinal(to_encrypt); // <=========== error
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
lleva a
javax.crypto.IllegalBlockSizeException: data not block size aligned
at org.bouncycastle2.jce.provider.JCEBlockCipher.engineDoFinal(JCEBlockCipher.java:686)
at javax.crypto.Cipher.doFinal(Cipher.java:1171)
Gracias.
Si utilizó el relleno para usted, ¿podría compartir el código fijo? – Shivam657