1
0
mirror of synced 2025-12-16 12:25:33 +08:00

#659 小程序增加上报用户数据后台接口

This commit is contained in:
Binary Wang
2018-07-11 23:30:56 +08:00
parent 0678e22e4e
commit 4289bd5350
5 changed files with 113 additions and 29 deletions

View File

@@ -0,0 +1,40 @@
package me.chanjar.weixin.common.util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Hex;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
/**
* <pre>
* 签名工具类
* Created by BinaryWang on 2018/7/11.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Slf4j
public class SignUtils {
/**
* HmacSHA256 签名算法
*
* @param message 签名数据
* @param key 签名密钥
*/
public static String createHmacSha256Sign(String message, String key) {
try {
Mac sha256 = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), "HmacSHA256");
sha256.init(secretKeySpec);
byte[] bytes = sha256.doFinal(message.getBytes());
return Hex.encodeHexString(bytes).toUpperCase();
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
SignUtils.log.error(e.getMessage(), e);
}
return null;
}
}