package com.sf.common.utils.sign;

import java.security.MessageDigest;

/**
 * Sha256加密方法
 * 
 * @author ztzh
 */
public class Sha265Utils
{
    private static final String SHA_256_ALGORITHM = "SHA-256";
    public static String encrypt(byte[] data) throws Exception {
        //获取SHA-256算法实例
        MessageDigest messageDigest = MessageDigest.getInstance(SHA_256_ALGORITHM);
        //计算散列值
        byte[] digest = messageDigest.digest(data);
        StringBuilder stringBuilder = new StringBuilder();
        //将byte数组转换为15进制字符串
        for (byte b : digest) {
            stringBuilder.append(Integer.toHexString((b & 0xFF) | 0x100).toUpperCase(), 1, 3);
        }
        return stringBuilder.toString();
    }

}
