Here you can find the source of encrypt(byte[] content, String password)
public static byte[] encrypt(byte[] content, String password)
//package com.java2s; import java.security.SecureRandom; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; public class Main { public static byte[] encrypt(byte[] content, String password) { byte[] result = null; try {/*w w w . jav a 2s . c o m*/ SecretKeySpec key = new SecretKeySpec( getRawKey(password.getBytes()), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, key); result = cipher.doFinal(content); } catch (Exception e) { e.printStackTrace(); } return result; } private static byte[] getRawKey(byte[] seed) throws Exception { KeyGenerator kgen = KeyGenerator.getInstance("AES"); SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto"); sr.setSeed(seed); kgen.init(128, sr); SecretKey skey = kgen.generateKey(); byte[] raw = skey.getEncoded(); return raw; } }