mirror of
https://gitee.com/jzsw-it/yexuejc-base.git
synced 2025-06-03 04:24:05 +08:00
[update] AES类兼容ECB(虽然不再建议利用)
This commit is contained in:
parent
1415200b1a
commit
cf8231017d
@ -8,6 +8,7 @@ yexuejc-base 更新记录
|
||||
1. [FileUtil.java](src/main/java/com/yexuejc/base/util/FileUtil.java)增加读取大文件自定义方法和单纯读取方法
|
||||
2. JsonUtil 增加objToMap;优化obj2Json
|
||||
3. DateUtil 标准化日期时间的转换函数
|
||||
4. [AES.java](src/main/java/com/yexuejc/base/encrypt/AES.java) 兼容ECB(虽然不再建议利用)
|
||||
---
|
||||
|
||||
#### version :1.5.2-jre11
|
||||
|
@ -93,7 +93,10 @@ public class AES {
|
||||
byte[] plaintext = new byte[plaintextLength];
|
||||
System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);
|
||||
SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(charset), AES_ALGORITHM);
|
||||
IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes(charset));
|
||||
IvParameterSpec ivspec = null;
|
||||
if(!algorithm.name.contains("ECB")){
|
||||
ivspec = new IvParameterSpec(iv.getBytes(charset));
|
||||
}
|
||||
cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
|
||||
byte[] encrypted = cipher.doFinal(plaintext);
|
||||
return Base64.getEncoder().encodeToString(encrypted);
|
||||
@ -115,7 +118,10 @@ public class AES {
|
||||
byte[] encrypted = Base64.getDecoder().decode(data);
|
||||
Cipher cipher = Cipher.getInstance(algorithm.name);
|
||||
SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(charset), AES_ALGORITHM);
|
||||
IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes(charset));
|
||||
IvParameterSpec ivspec = null;
|
||||
if(!algorithm.name.contains("ECB")){
|
||||
ivspec = new IvParameterSpec(iv.getBytes(charset));
|
||||
}
|
||||
cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);
|
||||
byte[] original = cipher.doFinal(encrypted);
|
||||
return new String(original, charset).trim();
|
||||
|
Loading…
x
Reference in New Issue
Block a user