AES알고리즘
http://marcof.tistory.com/95
위키
http://ko.wikipedia.org/wiki/고급_암호화_표준
/** * AES 방식의 암호화 * * @param message * @return * @throws Exception */ public static String encrypt(String message) throws Exception { // use key coss2 SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(), “AES”); // Instantiate the cipher Cipher cipher = Cipher.getInstance(“AES”); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); byte[] encrypted = cipher.doFinal(message.getBytes()); return byteArrayToHex(encrypted); }
/** * AES 방식의 복호화 * * @param message * @return * @throws Exception */ public static String decrypt(String encrypted) throws Exception { // use key coss2 SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(), “AES”); Cipher cipher = Cipher.getInstance(“AES”); cipher.init(Cipher.DECRYPT_MODE, skeySpec); byte[] original = cipher.doFinal(hexToByteArray(encrypted)); String originalString = new String(original); return originalString; } public static void main(String[] args) { try { String encrypt = encrypt(“test1234″); System.out.println(“origin str = “+”test1234″); System.out.println(“encrypt str = “+encrypt); String decrypt = decrypt(encrypt); System.out.println(“decrypt str = “+decrypt); } catch (Exception e) { e.printStackTrace(); } } }