Java tutorial
//package com.java2s; //License from project: Apache License import javax.crypto.spec.SecretKeySpec; public class Main { private static SecretKeySpec createKey(String key) { byte[] data = null; if (key == null) { key = ""; } StringBuffer sb = new StringBuffer(16); sb.append(key); while (sb.length() < 16) { sb.append("0"); } if (sb.length() > 16) { sb.setLength(16); } try { data = sb.toString().getBytes("UTF-8"); } catch (Exception e) { e.printStackTrace(); } return new SecretKeySpec(data, "AES"); } }