环境:Eclipse+jdk8
导入包:commons-codec-1.8.jar
代码:
package com.test.shautil;
import java.security.MessageDigest;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
public class shatest {
/** * commons-codec实现SHA1加密 * @param message */public static void SHA1(String message) { System.out.println("SHA1加密后为"+DigestUtils.sha1Hex(message));} /** * commons-codec实现SHA256加密 * @param message */public static void SHA256(String message) { MessageDigest ccSHA256=DigestUtils.getSha256Digest(); byte[] byteFinal=ccSHA256.digest(message.getBytes()); System.out.println("SHA256加密后为"+Hex.encodeHexString(byteFinal));} public static void main(String[] args) { // TODO Auto-generated method stub String message="jevirs123"; SHA1(message); SHA256(message);}}
网上都没找到类似的,有大神知道的吗,
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |