This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez 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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "password Encryption in WSAD environment" Watch "password Encryption in WSAD environment" New topic
Author

password Encryption in WSAD environment

Monoj Barma
Greenhorn

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?

[CODE]
public class TripleDESPasswordEncrypt
{
private String characterEncoding = "ASCII";
//private String characterEncoding;
private Cipher encryptCipher;
private Cipher decryptCipher;


public TripleDESPasswordEncrypt() throws Exception
{
Provider ibmjce = new com.ibm.crypto.provider.IBMJCE();
Security.addProvider(ibmjce);
KeyGenerator kg=KeyGenerator.getInstance("DESede");
kg.init(168);
SecretKey key = kg.generateKey();
this.characterEncoding = characterEncoding;
this.encryptCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
this.encryptCipher.init(javax.crypto.Cipher.ENCRYPT_MODE, key);
byte[]encodedParam=this.encryptCipher.getParameters().getEncoded();
System.out.println("Inside TripleDES instance");
this.decryptCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
AlgorithmParameters alParam=AlgorithmParameters.getInstance("DESede");
alParam.init(encodedParam);
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;
}

}
[CODE]


Thanks a lot!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: password Encryption in WSAD environment