实现Android和java互相加解密
完美支持中文
跨平台这种实现
还是一个原则
不要对参数采用默认实现
否则难以互通
核心函数如下,Android和java均如此
public static final String VIPARA = "0102030405060708";
public static final String bm = "GBK";
public static String encrypt(String dataPassword, String cleartext)
throws Exception {
IvParameterSpec zeroIv = new IvParameterSpec(VIPARA.getBytes());
SecretKeySpec key = new SecretKeySpec(dataPassword.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key, zeroIv);
byte[] encryptedData = cipher.doFinal(cleartext.getBytes(bm));
return Base64.encode(encryptedData);
}
public static String decrypt(Strin