com.zopen.wechat.mp.dto.jssdk.UtilSha1 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zopen-ato-starter Show documentation
Show all versions of zopen-ato-starter Show documentation
Alibaba Tencent And Others For Spring Boot.
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;
}
}
}