AES加密解密

1、AES-Zip压缩-Base64 加密

//AES加密
public static String _aesEncrypt(String str) throws Exception {
    String key = "1234567800000000";//密钥
    if (str == null || key == null) return null;
    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");// 创建密码器
    cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key.getBytes("utf-8"), "AES"));// 初始化 
    byte[] bytes = cipher.doFinal(str.getBytes("utf-8"));//1-加密
    byte[] zipStr = ZipUtils.ecompress(bytes);//2-压缩        
    return new BASE64Encoder().encode(zipStr);//3-base64
}
//AES解密
public static String _aesDecrypt(byte[] str) throws Exception {
    if (null == str) return null;
    byte[] buff= Base64.decodeBase64(str);
    byte[] miwen=ZipUtils.decompress(buff);//解压缩    
    String key = "1234567800000000";//秘钥 
    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
    cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key.getBytes("utf-8"), "AES"));
    byte[] bytes = cipher.doFinal(miwen);      
    return new String(bytes, "utf-8");
}

未完待续...

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容