AES加密叫Advanced Encryption Standard,是高級加密標準。java
這個標準用來替代原來的DESapp
優勢:ui
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
private static String encrypt(String inputKey, String inputContent) { try { SecretKeySpec secretKeySpec = new SecretKeySpec(inputKey.getBytes("UTF-8"), "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); byte[] encodedBytes = cipher.doFinal(inputContent.getBytes("UTF-8")); StringBuilder builder = new StringBuilder(); for (byte b : encodedBytes) { String plainText = Integer.toHexString(0xff & b); if (plainText.length() < 2) plainText = "0" + plainText; builder.append(plainText); } return builder.toString(); } catch (Exception e) { System.out.println(e.getMessage()); } return ""; }
如上代碼的正確性有待商榷。編碼