Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

password Encryption in WSAD environment

 
Monoj Barma
Greenhorn
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?

[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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic