1.AES 密钥+偏移进行加密解密 结合 base64对加密之后的字节数组进行编码解码(代码如下)
最近项目上需要用到数据加密存储,查询资料后发现目前AES加密安全度非常高,具体原理可自行百度。但经网上搜到的实现示例运行都有各种问题,耗时一上午,终于调试运行成功,闲话少说,直接上代码。
参考gfaming的博客
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class AesEncodeUtil {
//初始向量(偏移)
public static final String VIPARA = "aabbccddeeffgghh"; //AES 为16bytes. DES 为8bytes
//编码方式
public static final String bm = "UTF-8";
//私钥 (密钥)
private static final String ASE_KEY="aabbccddeeffgghh"; //AES固定格式为128/192/256 bits.即:16/24/32bytes。DES固定格式为128bits,即8bytes。
/**
* 加密
*
* @param cleartext 加密前的字符串
* @return