AES with 256 bit key size and apply password

I wan to encrypt/decrypt large data with AES with 256 bit key size. I want to ecrypt/decrypt data with a password. I dont know how to add this password. Anyone please help me as it is urgent.import java.security.*;

import javax.crypto.*;

import javax.crypto.spec.*;

import java.io.*;

/**

* This program generates a AES key, retrieves its raw bytes, and

* then reinstantiates a AES key from the key bytes.

* The reinstantiated key is used to initialize a AES cipher for

* encryption and decryption.

*/

publicclass JavaAES256

{

publicstaticvoid main(String[] args)throws Exception

{

String message="This is just an example";

// Get the KeyGenerator

KeyGenerator kgen = KeyGenerator.getInstance("AES");

kgen.init(256);// 192 and 256 bits may not be available

// Generate the secret key specs.

SecretKey skey = kgen.generateKey();

byte[] raw = skey.getEncoded();

SecretKeySpec skeySpec =new SecretKeySpec(raw,"AES");

// Instantiate the cipher

Cipher cipher = Cipher.getInstance("AES");

cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

byte[] encrypted = cipher.doFinal("This is just an example".getBytes());

System.out.println("encrypted string: " + asHex(encrypted));

cipher.init(Cipher.DECRYPT_MODE, skeySpec);

byte[] original = cipher.doFinal(encrypted);

String originalString =new String(original);

System.out.println("Original string: " +

originalString +" " + asHex(original));

}

/**

* Turns array of bytes into string

*

* @param bufArray of bytes to convert to hex string

* @returnGenerated hex string

*/

publicstatic String asHex (byte buf[])

{

StringBuffer strbuf =new StringBuffer(buf.length * 2);

int i;

for (i = 0; i < buf.length; i++)

{

if (((int) buf[i] & 0xff) < 0x10)

strbuf.append("0");

strbuf.append(Long.toString((int) buf[i] & 0xff, 16));

}

return strbuf.toString();

}

}

[3570 byte] By [AamirAthara] at [2007-10-3 11:53:49]
# 1
Check out Passphrase Based Encryption (PBE) and use in conjunction with CipherInputStream and/or CipherOutputStream.
sabre150a at 2007-7-15 14:28:20 > top of Java-index,Security,Cryptography...
# 2
I have the same question.PBE does not support AES.Then how to use AES with PBE? Hope anyone can help
BernieKea at 2007-7-15 14:28:20 > top of Java-index,Security,Cryptography...
# 3

> I have the same question.PBE does not support

> AES.Then how to use AES with PBE? Hope anyone can help

BouncyCastle provider supports

Cipher.PBEWITHSHAAND256BITAES-CBC-BC

Cipher.PBEWITHMD5AND192BITAES-CBC-OPENSSL

Cipher.PBEWITHMD5AND128BITAES-CBC-OPENSSL

Cipher.PBEWITHSHAAND192BITAES-CBC-BC

Cipher.PBEWITHMD5AND256BITAES-CBC-OPENSSL

Cipher.PBEWITHSHA256AND128BITAES-CBC-BC

Cipher.PBEWITHSHA256AND192BITAES-CBC-BC

Cipher.PBEWITHSHAAND128BITAES-CBC-BC

Cipher.PBEWITHSHA256AND256BITAES-CBC-BC

sabre150a at 2007-7-15 14:28:20 > top of Java-index,Security,Cryptography...