Hi,
I am trying to implement security via
java encryption for my application. I already went through all the posts listed in the intermediate and advanced sections related to security before trying it out. I followed the installation instructions carefully for JCE and did the required modifications to the java.security and java.policy files. But when I compile my code still I am getting
java.security.NoSuchAlgorithmException: Algorithm DES not available
at javax.crypto.SunJCE_b.a(DashoA6275)
at javax.crypto.KeyGenerator.getInstance(DashoA6275)
at samples.DesEncrypterTest.main(DesEncrypterTest.java:28)
The code is the following
package samples;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/
import javax.crypto.*;
import javax.crypto.spec.*;
import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;
public class DesEncrypterTest {
public DesEncrypterTest() {
}
public static void main(
String[] args) {
try
{
// Generate a temporary key. In practice, you would save this key.
// See also e464 Encrypting with DES Using a Pass Phrase.
SecretKey key = KeyGenerator.getInstance("DES").generateKey();
// Create encrypter/decrypter class
DesEncrypter encrypter = new DesEncrypter(key);
byte[] keyBytes = key.getEncoded();
System.out.println("Generated key using Bytes :" + keyBytes.toString());
System.out.println("Generated key using the the getFormat Method :" + key.getFormat());
System.out.println("Generated key using the the toString Method :" + key.toString());
// Encrypt
String userName = encrypter.encrypt("dpyusinta01");
String password = encrypter.encrypt("dctmbase");
System.out.println("Encrypted User Name is :" + userName);
System.out.println("Encrypted Password is :" + password);
// Decrypt
String user = encrypter.decrypt(userName);
String passwd = encrypter.decrypt(password);
System.out.println("Decrypted User Name is :" + userName);
System.out.println("Decrypted password is :" + passwd);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Any help would be deeply appreciated
Thanks
Seshan