Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

password Encryption in WSAD environment

Monoj Barma
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
i am working on the following program for encrypting password. Works fine as standalone java program, encrypt and decrypt the password but when i install the code in WSAD5.1 env i get Exception "final block not properrly padded" and "input lenght not multiple of 8 bytes".
Does anyone have any idea on this?

public class TripleDESPasswordEncrypt
private String characterEncoding = "ASCII";
//private String characterEncoding;
private Cipher encryptCipher;
private Cipher decryptCipher;

public TripleDESPasswordEncrypt() throws Exception
Provider ibmjce = new;
KeyGenerator kg=KeyGenerator.getInstance("DESede");
SecretKey key = kg.generateKey();
this.characterEncoding = characterEncoding;
this.encryptCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
this.encryptCipher.init(javax.crypto.Cipher.ENCRYPT_MODE, key);
System.out.println("Inside TripleDES instance");
this.decryptCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
AlgorithmParameters alParam=AlgorithmParameters.getInstance("DESede");
this.decryptCipher.init(javax.crypto.Cipher.DECRYPT_MODE, key,alParam);

synchronized public String encrypt(String password) throws Exception
if (!password.matches("[ -~]{6,}"))
throw new IllegalArgumentException("Password must be printable ASCII");
System.out.println("Password ....................[" + password + "]");

byte[] passwordBytes = password.getBytes(characterEncoding);
byte[] encryptedPasswordBytes =this.encryptCipher.doFinal(passwordBytes);
String encodedEncryptedPassword =new String(encryptedPasswordBytes);
return encodedEncryptedPassword;

synchronized public String decrypt(String encodedEncryptedPassword) throws Exception

byte[] passwordBytes =this.decryptCipher.doFinal(encodedEncryptedPassword.getBytes());
String recoveredPassword = new String(passwordBytes,characterEncoding);
return recoveredPassword;


Thanks a lot!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic