package net.oschina.crypto;

import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

public class Test {
	public static byte[] encrypt(String content, String password) {
		try {
			KeyGenerator kgen = KeyGenerator.getInstance("AES");
			kgen.init(128, new SecureRandom(password.getBytes()));
			SecretKey secretKey = kgen.generateKey();
			byte[] enCodeFormat = secretKey.getEncoded();
			SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
			Cipher cipher = Cipher.getInstance("AES");// 
			byte[] byteContent = content.getBytes("utf-8");
			cipher.init(Cipher.ENCRYPT_MODE, key);// ʼ
			byte[] result = cipher.doFinal(byteContent);
			return result; // 
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		} catch (NoSuchPaddingException e) {
			e.printStackTrace();
		} catch (InvalidKeyException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (IllegalBlockSizeException e) {
			e.printStackTrace();
		} catch (BadPaddingException e) {
			e.printStackTrace();
		}
		return null;
	}
}

@@ -457,16 +457,41 @@
 eySpec;%0A
+/**%0A * %E5%88%9D%E6%AD%A5%E5%AE%9E%E7%8E%B0%E7%9A%84%E5%8A%A0%E5%AF%86%E6%89%80%E5%8F%91%EF%BC%8C%E5%A4%87%E7%94%A8%0A * */
 %0Apublic 
@@ -895,16 +895,26 @@
 ES%22);// 
+%C2%B4%C2%B4%C2%BD%C2%A8%C3%83%C3%9C%C3%82%C3%AB%C3%86%C3%B7
 %0A%09%09%09byte
@@ -1005,9 +1005,14 @@
 ;// 
-%CA%BC
+%C2%B3%C3%B5%C3%8A%C2%BC%C2%BB%C2%AF
 %0A%09%09%09
@@ -1077,16 +1077,20 @@
 ult; // 
+%C2%BC%C3%93%C3%83%C3%9C
 %0A%09%09%7D cat

Update Test.java