All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zopen.wechat.mp.dto.jssdk.UtilSha1 Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
package com.zopen.wechat.mp.dto.jssdk;

import com.zcj.util.UtilString;

import java.security.MessageDigest;

/**
 * Sha1 签名
 *
 * @author [email protected]
 * @since 2020/1/16
 */
public class UtilSha1 {

    public static String encode(String value) {
        if (UtilString.isBlank(value)) {
            return null;
        }
        try {
            MessageDigest sha = MessageDigest.getInstance("SHA");
            byte[] byteArray = value.getBytes("UTF-8");
            byte[] md5Bytes = sha.digest(byteArray);
            StringBuffer hexValue = new StringBuffer();
            for (int i = 0; i < md5Bytes.length; i++) {
                int val = ((int) md5Bytes[i]) & 0xff;
                if (val < 16) {
                    hexValue.append("0");
                }
                hexValue.append(Integer.toHexString(val));
            }
            return hexValue.toString();
        } catch (Exception e) {
            return null;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy