在使用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);