Apache Commons Codec
The Apache Commons Codec package contains simple encoder and decoders for various formats such as Base64 and Hexadecimal. In addition to these widely used encoders and decoders, the codec package also maintains a collection of phonetic encoding utilities.
添加依赖到项目中:
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
demo如下:
package org.example.temp;
import org.apache.commons.codec.digest.DigestUtils;
public class Demo {
public static void main(String[] args) {
System.out.println(DigestUtils.sha256Hex("加密你自己的数据"));
}
}
结果如下:
a502cce37f3ebcfa646c1fab3311afb265f145fdadb844ba28adc62eb2ab21ff