I have implemented a wrapper class for encrypting and decrypting passwords. I have compiled and successfully tested this class on a Win32 environment with no problem. Once deployed on a debian/GNU linux installation attempting to run the same code results in the following exception being thrown. Both systems are running the same version of Sun Java (which is 1.4)
java.security.NoSuchAlgorithmException: Cannot find any provider supporting AES/ECB/PKCS5Padding
Here is a (truncated) copy of the code I've developed...
public class CryptCodec
{
private static CryptCodec ourInstance = null;
private static final Log log = LogFactory.getLog(CryptCodec.class);
private String algorithm;
private String mode;
private String padding;
private byte[] secretKey;
.
.
.
private CryptCodec()
{
Provider sunJce = new com.sun.crypto.provider.SunJCE();
Security.addProvider(sunJce);
.
.
.
}
private String getTransformation()
{
//returns AES/ECB/PKCS5Padding
return algorithm + "/" + mode + "/" + padding;
}
public String encrypt(String plain) throws CryptCodecException
{
log.debug("Encrypting plain string '" + plain + "'using key: '" + new String(Base64.encode(secretKey)) + "'");
byte[] bytes = new byte[0];
try
{
Cipher cipher = Cipher.getInstance(getTransformation());
SecretKeySpec sKeySpec = new SecretKeySpec(secretKey, algorithm);
cipher.init(Cipher.ENCRYPT_MODE, sKeySpec);
bytes = cipher.doFinal(plain.getBytes());
}
catch (GeneralSecurityException e)
{
throw new CryptCodecException("An exception was thrown whilst trying to encrypt", e);
}
return new String(Base64.encode(bytes));
}
public String decrypt(String crypt) throws CryptCodecException
{
log.debug("Decrypting plain string '" + crypt + "'using key: '" + new String(Base64.encode(secretKey)) + "'");
byte[] bytes = new byte[0];
try
{
Cipher cipher = Cipher.getInstance(getTransformation());
SecretKeySpec sKeySpec = new SecretKeySpec(secretKey, algorithm);
cipher.init(Cipher.DECRYPT_MODE, sKeySpec);
byte[] decoded = Base64.decode(crypt.getBytes());
bytes = cipher.doFinal(decoded);
}
catch (GeneralSecurityException e)
{
throw new CryptCodecException("An exception was thrown whilst trying to decrypt", e);
}
return new String(bytes);
}
}
Does anyone have any ideas? I'd really appreciate it if someone could point me toward a possible cause for this problem.
Cheers