在使用Spring框架的时候,我们会对一些重要的密码进行加密可以使用MD5,其工具类是DigestUtils;
DigestUtils相同名字的工具类有两个:
1. Spring框架继承的:
import org.springframework.util.DigestUtils;
String inputMD = "deqwfdeqe";
DigestUtils.md5DigestAsHex(inputMD.getBytes());
2. apaceh commons-codec 加密工具类 DigestUtils
依赖的maven:
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
String src = "dklwhjwhv";
DigestUtils.md5Hex(src);