import java.io.UnsupportedEncodingException;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import org.springframework.util.Base64Utils;
/**
*
* created by Jeeson
*
*/
public class AesUtils {
/**
* 根据IMEI获取AES code
*
* @param content
* @return
*/
public static byte[] aesEncrypt(String content,String aeskey) {
try {
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
SecretKeySpec key = new SecretKeySpec(Base64Utils.decodeFromString(aeskey), "AES");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] result = cipher.doFinal(content.getBytes("utf-8"));
return result;
} catch (Exception e) {
// e.printStackTrace();
return null;
}
}
/**
* 根据AES_CODE获取IMEI
* new String()变回字符串
* @param content
* @return
*/
public static byte[] aseDecrypt(byte[] content,String aeskey) {
try {
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
SecretKeySpec key = new SecretKeySpec(Base64Utils.decodeFromString(aeskey), "AES");
cipher.init(Cipher.DECRYPT_MODE, key);
return cipher.doFinal(content);
} catch (Exception e) {
// e.printStackTrace();
return null;
}
}
public static void main(String[] args) throws UnsupportedEncodingException {
// System.out.println(new
// String(Base64Utils.decodeFromString(AseCrypto.SEC_KEY)));
}
}
Aes工具类
于 2023-11-07 08:30:07 首次发布
696

被折叠的 条评论
为什么被折叠?



