最近项目中产品要求后台返回的数据以加密的形式返给我,这样子的话,app拿到的数据就是加密过的了,aes解密之前还要先用base64解密,接到新需求之后开始网上各种搜,因为本人也是小菜鸟一枚,只能通过先搬运代码再进行操作。好了不多说了,上代码:
public class AESUtils {
/*
* 加密用的Key 可以用26个字母和数字组成 此处使用AES-128-CBC加密模式,key需要为16位。
*/
private String sKey;
private String ivParameter = "1234567890123456";
private static AESUtils instance = null;
private AESUtils(String sKey) {
this.sKey = sKey;
}
public static AESUtils getInstance(String sKey) {
if (instance == null)
instance = new AESUtils(sKey);
return instance;
}
// 加密
public static String encrypt(String encData ,String secretKey,String vector) throws Exception {
if(secretKey == null) {
return null;
}
if(secretKey.length() != 16) {
return null;
}
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
byte[] raw = secretKey

本文介绍了在Android项目中如何使用AES加密解密技术,针对后台返回的加密数据进行处理。首先通过Base64解密,然后使用AES进行解密操作。提供了相关代码示例,适合初学者参考。

539

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



