I want to encrypt the passwords which are stored in my xml configuration file. I read thru some articles and found some examples. But when i executed them, i get an exception,
java.security.NoSuchAlgorithmException: Algorithm DES not available
at javax.crypto.SunJCE_b.a(DashoA6275)
at javax.crypto.KeyGenerator.getInstance(DashoA6275)
at com.pfizer.groton.di.ceg.encryption.Encrypt.getEncryptedString(Encrypt.java:20)
at com.pfizer.groton.di.ceg.encryption.Encrypt.main(Encrypt.java:43)
The method is which i am using is,
public static String getEncryptedString(String input)throws Exception{
Security.addProvider( new com.sun.crypto.provider.SunJCE() );
Key key = null;
KeyGenerator kg = KeyGenerator.getInstance("DES");
key = kg.generateKey();
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[]inputBytes = input.getBytes("UTF8");
byte[] outputBytes = cipher.doFinal(inputBytes);
BASE64Encoder encoder = new BASE64Encoder();
String base64 = encoder.encode(outputBytes);
return base64;
Any thoughts on why it is throwing this exception is greatly appreciated