

import java.security.*; import javax.crypto.*; import javax.crypto.spec.DESKeySpec;
class EncryptAndDecrypt {
public static void main (String[] args) throws Exception{ //KeyPairGenerator keygenerator = KeyPairGenerator.getInstance("RC4"); SecretKeyFactory key = SecretKeyFactory.getInstance("DES"); SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN"); //keygenerator.initialize(1024, random); byte[] desKeyData = { (byte)0x01, (byte)0x02, (byte)0x03, (byte)0x04, (byte)0x05, (byte)0x06, (byte)0x07, (byte)0x08 }; DESKeySpec desKeySpec = new DESKeySpec(desKeyData);
//KeyPair keypair = keygenerator.generateKeyPair(); Key keys = key.generateSecret(desKeySpec); //PrivateKey privateKey = keypair.getPrivate(); //PublicKey publicKey = keypair.getPublic();
Cipher cipher = Cipher.getInstance("DES");
System.out.println("publicKey="+keys.toString()); //System.out.println("privateKey="+privateKey.toString());
cipher.init(Cipher.ENCRYPT_MODE, keys); String st= "Welcome"; byte[] cleartext = null; cleartext = st.getBytes(); byte[] ciphertext = null; ciphertext = cipher.doFinal(cleartext); System.out.println("the encrypted text is: " + ciphertext.toString());
cipher.init(Cipher.DECRYPT_MODE, keys); byte[] cleartext1 = cipher.doFinal(ciphertext); System.out.println("the decrypted cleartext is: " + new String(cleartext1)); } }

http://www.roseindia.net/answers/viewqa/Java-Beginners/26017-Java-Encryption-using-AES-with-key-password-.html
http://www.roseindia.net/answers/viewqa/Java-Beginners/26020-AES-Decryption-using-key-password-.html
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.