Comments (8)
AES属于对称加密,特殊要求的加密模式请使用SymmetricCrypto传入字符串的算法。前提是JDK支持。可以看下这部分文档:http://hutool.mydoc.io/?t=233546
from hutool.
自己用Cipher类实现了,这部分文档就没有涉及到我问的问题
from hutool.
Hutool本质上是封装了Cipher。如果方便,欢迎提供Cipher实现的代码。我看Hutool如何实现,我会补充到文档。谢谢~
from hutool.
好的,我是参考了中文文档 http://www.matools.com/manual/1000和
在线测试http://tool.chacuo.net/cryptaes ,希望有所帮助
具体如下:
/**
* ASE-128-CBC加密
* @param src 加密内容
* @param key 密钥 16位
* @param iv 偏移量 16
* @return
* @throws Exception
*/
public static String aesEncrypt(String src, String key,String iv) throws Exception {
String encodingFormat = "UTF-8";
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
byte[] raw = key.getBytes();
SecretKeySpec secretKeySpec = new SecretKeySpec(raw, "AES");
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv.getBytes());
// 使用CBC模式,需要一个向量vi,增加加密算法强度
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);
byte[] encrypted = cipher.doFinal(src.getBytes(encodingFormat));
return new BASE64Encoder().encode(encrypted);
}
public static void main(String[] args) {
String result = null;
try {
result = aesEncrypt("123", "0CoJUm6Qyw8W8jud", "0102030405060708");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(result);
}
from hutool.
Sorry关于这个问题这么久回复。经过排查已经找到问题,3.3.0中会修复此问题。
新版可以直接这么使用:
DES des = new DES(Mode.CBC, Padding.PKCS5Padding, "0CoJUm6Qyw8W8jud".getBytes(), "01020304".getBytes());
from hutool.
@looly 请问java 支持AES 256位偏移量嘛
from hutool.
请问下,如果要实现AES256位加密,是否生成的密钥是256位即可?也就是长度是32个字节
from hutool.
@planwk 是的,jce 实现的内部会根据传入密钥的 size 自动计算轮数。
from hutool.
Related Issues (20)
- HttpRequest上传大文件,size超过Integer.max问题 HOT 1
- NumberUtil.roundStr; Out-of-bounds Write vulnerability with High severity found HOT 3
- 求助,有没有(或者能不能提供)这样的功能:我想用 ConcurrencyTester 底层的 CountDownLatch 功能来保证所有的线程是同时开始执行的,但是我并不是只有一种类型的任务,不同的线程有可能执行的是不同的任务。 HOT 1
- 前端是鸿蒙,使用鸿蒙的sm2加密出来的数据是Uint8Array整型数组,在后台这边使用hutool这边应该怎么解析呢? HOT 10
- UAUtils 判断是否移动端 HOT 1
- JSONUtil.toJsonStr(Object obj) 数组下标越界 HOT 2
- CVE-2023-51075
- Convert.toInt得到的结果不正确 HOT 2
- 使用的是4.4.1的版本,想问下这个版本SimpleCache 是否存在死锁的场景 HOT 1
- SshjSftp cd逻辑有误 返回布尔值总是false HOT 1
- Setting.autoLoad 中 WatchMonitor监听回调问题 HOT 1
- excel导入日期相关问题 HOT 3
- HtmlUtil.removeHtmlAttr HtmlUtil.removeAllHtmlAttr 无法处理属性值里有空格的标签; 无法处理闭标签有属性值
- hutool-json toBean后的对象在dubbo3协议下传输序列化异常 HOT 7
- RSA 解密的时候出现了乱码 HOT 3
- 使用Convert转换实体对象异常 HOT 2
- 邮箱工具不支持openjdk17对应的jakarta.mail HOT 1
- ExcelUtil.getReader读取文件后更新某行某列,原文件无变化 HOT 1
- DateException: No format fit for date String HOT 4
- `Hutool.getAllUtils()` 获取不到 Base64 等工具类 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hutool.