This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Websphere and the fly likes password Encryption in WSAD environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "password Encryption in WSAD environment" Watch "password Encryption in WSAD environment" New topic

password Encryption in WSAD environment

Monoj Barma

Joined: Oct 20, 2005
Posts: 9
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!
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: password Encryption in WSAD environment
It's not a secret anymore!