dcsimg
BadPaddingExeption with DES
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Paul_Hunnisett
Posted On:   Monday, August 22, 2005 09:56 AM

I'm having trouble decrypting a String that was encrypted using DES. I always get a BadPaddingException. The code that generates the exception is: String result = ""; Cipher cipher = null; try { cipher = Cipher.getInstance("DES"); } 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 = ciphe   More>>

I'm having trouble decrypting a String that was encrypted using DES. I always get a BadPaddingException.

The code that generates the exception is:

			
String result = "";
Cipher cipher = null;
try {
cipher = Cipher.getInstance("DES");
} 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);
}
return result;


The class that generates the key is:

			
SecretKey key = null;
try {
key = KeyGenerator.getInstance("DES").generateKey();
} catch (NoSuchAlgorithmException e) {
System.out.println("Arse: " + e);
}


Can anyone help me figure out why I'm getting this exception?

   <<Less
About | Sitemap | Contact