package com.dataplatform.encrypt;
import org.apache.commons.codec.digest.DigestUtils;
/**
* sha256加密:单向操作,不可逆
*
* @author
* @date 2018-12-03
* @version 1.0 字符串->十六进制串
* 需要引入依赖
* <dependency>
* <groupId>commons-codec</groupId>
* <artifactId>commons-codec</artifactId>
* <version>1.6</version>
* </dependency>
* md5和sha256的区别:
(1)md5:不可逆,速度较快;
(2)sha256:不可逆,安全性较高,比MD5慢一些
*/
public class Sha256Utils {
/**
*
* @param input
* @return
*/
public static String sha256Encode(String input) {
return DigestUtils.sha256Hex(input.getBytes());
}
public static void main(String[] args) {
String name = "zhangsan";
System.out.println(sha256Encode(name));
}
}