-
@param iv 加密的偏移量
-
@return 输出Hex十六进制再次加密的结果
**/
public static String encryptCRT(byte[] content, String key, String iv) {
String encodeStr = “”;
try {
//产生密钥
byte[] keyBytes = key.getBytes();
SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, “AES”);
//构建Cipher对象,需要传入一个字符串,格式必须为"algorithm/mode/padding"或者"algorithm/",意为"算法/加密模式/填充方式"
Cipher cipher = Cipher.getInstance(“AES/CTR/PKCS5Padding”);
//初始化Cipher对象
byte[] ivBytes = iv.getBytes();
IvParameterSpec ivParameterSpec = new IvParameterSpec(ivBytes);
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);
//加密数据
byte[] resultBytes = cipher.doFinal(content);
//结果用Hex十六进制转码
encodeStr = new String(Hex.encode(resultBytes));
return encodeStr;
} ca