dcsimg
IllegalBlockSizeException
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Paul_Hunnisett
Posted On:   Wednesday, August 24, 2005 11:56 AM

I'm trying to perform an encrypt and decrypt on a simple string using blowfish. The encryption always works perfectly well. The decryption, however, occasionally throws the following: javax.crypto.IllegalBlockSizeException: Input length (with padding) not multiple of 8 bytes The code I'me using for the decrypt is as follows: Cipher cipher = null; try { cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding"); } catch (NoSuchAlgorithmException e) { LOG.error("Could not use algorithm",e); } catch (NoSuchPaddingException e) { LOG.error(e); } try { cipher.init(Cipher.DECRYPT_MODE,getKey()); } catch (Inval   More>>

I'm trying to perform an encrypt and decrypt on a simple string using blowfish. The encryption always works perfectly well. The decryption, however, occasionally throws the following:

			
javax.crypto.IllegalBlockSizeException: Input length (with padding) not multiple of 8 bytes


The code I'me using for the decrypt is as follows:

			
Cipher cipher = null;
try {
cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
} catch (NoSuchAlgorithmException e) {
LOG.error("Could not use algorithm",e);
} catch (NoSuchPaddingException e) {
LOG.error(e);
}
try {
cipher.init(Cipher.DECRYPT_MODE,getKey());
} catch (InvalidKeyException e) {
LOG.error("The key is not valid",e);
}

byte[] decoded = Base64.decode(coded);
try {
byte[] decrypted = cipher.doFinal(decoded);
result = new String(decrypted,"UTF-8");
} catch (Exception e) {
LOG.error("Problem decrypting the string",e);
}


I'm not getting this error every time - only some of the time. The getKey() method attempts to retrieve a key from a database or creates one if it can't. I'm not getting any errors to indicate that it's failing to get the key...

   <<Less
About | Sitemap | Contact