标签:替代 build vax utf-8 imp key mode import tco
AES加密叫Advanced Encryption Standard,是高级加密标准。
这个标准用来替代原来的DES
优点:
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 ""; }
如上代码的正确性有待商榷。
标签:替代 build vax utf-8 imp key mode import tco
原文地址:http://www.cnblogs.com/shuada/p/7016635.html