Git Product home page Git Product logo

Comments (8)

looly avatar looly commented on May 10, 2024

AES属于对称加密,特殊要求的加密模式请使用SymmetricCrypto传入字符串的算法。前提是JDK支持。可以看下这部分文档:http://hutool.mydoc.io/?t=233546

from hutool.

CharleyXu avatar CharleyXu commented on May 10, 2024

自己用Cipher类实现了,这部分文档就没有涉及到我问的问题

from hutool.

looly avatar looly commented on May 10, 2024

Hutool本质上是封装了Cipher。如果方便,欢迎提供Cipher实现的代码。我看Hutool如何实现,我会补充到文档。谢谢~

from hutool.

CharleyXu avatar CharleyXu commented on May 10, 2024

好的,我是参考了中文文档 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.

looly avatar looly commented on May 10, 2024

Sorry关于这个问题这么久回复。经过排查已经找到问题,3.3.0中会修复此问题。

新版可以直接这么使用:

DES des = new DES(Mode.CBC, Padding.PKCS5Padding, "0CoJUm6Qyw8W8jud".getBytes(), "01020304".getBytes());

from hutool.

MrSummer33 avatar MrSummer33 commented on May 10, 2024

@looly 请问java 支持AES 256位偏移量嘛

from hutool.

planwk avatar planwk commented on May 10, 2024

请问下,如果要实现AES256位加密,是否生成的密钥是256位即可?也就是长度是32个字节

from hutool.

changhr2013 avatar changhr2013 commented on May 10, 2024

@planwk 是的,jce 实现的内部会根据传入密钥的 size 自动计算轮数。

from hutool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.