-
@param content 要加密的内容
-
@param key 加密文件的秘钥
-
@param iv 加密的偏移量
-
@return 输出Hex十六进制再次加密的结果
**/
public static String encryptCRT(byte[] content, String key, String iv) {
String encodeStr = “”;
try {
//产生密钥
byte[] keyBytes = key.getBytes();
SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, “AES”);
//构建Cipher对象,需要传入一个字符串,格式必须为"algorithm/mode/padding"或者"algorithm/“,意为"算法/加密模式/填充方式”
Cipher cipher = Cipher.getInstance(“AES/CTR/PKCS5Padding”);
//初始化Cipher对象
byte[] ivBytes = iv.getBytes();
IvParameterSpec ivParameterSpec = new IvParameterSpec(ivBytes);
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);
//加密数据
byte[] resultBytes = cipher.doFinal(content);
//结果用Hex十六进制转码
encodeStr = new String(Hex.encode(resultBytes));
return encodeStr;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (InvalidAlgorithmParameterException e) {
e.printStackTrace();
}
return encodeStr;
}
/**
-
AES CTR 解密
-
填充为PKCS5
-
@param encode 加密过后的文件
-
@param iv 偏移量
-
@param key 秘钥文件
*/
public static String decryptCRT(String encode, String iv, String key) {
String decoded = “”;
try {
byte[] bytes = Hex.decode(encode);
IvParameterSpec ivSpec = new IvParameterSpec(
iv.getBytes());
Key keys = new SecretKeySpec(key.getBytes(), “AES”);
Cipher cipher = Cipher.getInstance(“AES/CTR/PKCS5Padding”);
cipher.init(Cipher.DECRYPT_MODE, keys, ivSpec);
byte[] ret = cipher.doFinal(bytes);
decoded = new String(ret);
return decoded.trim();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (InvalidAlgorithmParameterException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return decoded;
}
/**
-
AES ECB加密
-
填充为 “\0” noPadding
-
@param content 要加密的内容
-
@param key 加密文件的秘钥
-
@return 输出Base64的结果
**/
public static String encryptECB(byte[] content, String key) {
String encodeStr = “”;
try {
byte[] keyBytes = key.getBytes();
SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, “AES”);
Cipher cipher = Cipher.getInstance(“AES/ECB/NoPadding”);
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
//加密数据
int length = content.length;
int add = 16 - length % 16;
if (add == 16) {
add = 0;
}
byte[] contentNew = new byte[length + add];
//用’\0’加密
for (int i = 0; i < length + add; i++) {
if (i < length) {
contentNew[i] = content[i];
} else {
contentNew[i] = ‘\0’ ;
}
}
byte[] resultBytes = cipher.doFinal(contentNew);
//结果用Base64
encodeStr = new String(Base64Util.encode(resultBytes));
return encodeStr;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(资料价值较高,非无偿)
![](https://img-blog.csdnimg.cn/img_convert/d4335d32487c1b5f48a9bfc2e642fe43.jpeg)
Android进阶资料
以下的资料是近年来,我和一些朋友面试收集整理了很多大厂的面试真题和资料,还有来自如阿里、小米、爱奇艺等一线大厂的大牛整理的架构进阶资料。希望可以帮助到大家。
Android进阶核心笔记
百万年薪必刷面试题
最全Android进阶学习视频
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门即可获取!
。希望可以帮助到大家。
Android进阶核心笔记
[外链图片转存中…(img-VZ6Fnq8O-1711532856048)]
百万年薪必刷面试题
[外链图片转存中…(img-pBhEtaIv-1711532856048)]
最全Android进阶学习视频