签名算法

java

public class SignUtils {
    // appKey=HEQHMVoMKTfwWGTa123&appSecret=agcLiNjfDBhiRaebBbpJXnauqfTefXfZxVK&tenantSign=test&version=v1&timestamp=1582102489737
    public static String sign(String appKey, String appSecret, String tenantSign, String version, String timestamp) throws UnsupportedEncodingException {
        String params = "appKey="+appKey+"&appSecret="+appSecret+"&tenantSign="+tenantSign+"&version="+version+"&timestamp="+timestamp;
        MessageDigest md = DigestUtils.getSha256Digest();
        md.update(tenantSign.getBytes("UTF-8"));
        byte[] result = md.digest(params.getBytes("UTF-8"));
        return Hex.encodeHexString(result);
    }

}

golang

func GenSig( appKey ,  appSecret,  tenantSign,  version string,  timestamp int64) (string, error) {
        // appKey=HEQHMVoMKTfwWGTa123&appSecret=agcLiNjfDBhiRaebBbpJXnauqfTefXfZxVK&tenantSign=test&version=v1&timestamp=1582102489737
	params := fmt.Sprintf("appKey=%s&appSecret=%s&tenantSign=%s&version=%s&timestamp=%d",appKey ,  appSecret,  tenantSign,  version,  timestamp)
	h := sha256.New()
	h.Write([]byte(tenantSign))
	h.Write([]byte(params))
	hashInBytes := h.Sum(nil)
	signature := hex.EncodeToString(hashInBytes)
	//返回哈希值
	return signature, nil
}

python

posted @ 2020-02-20 15:02  HaimaBlog  阅读(273)  评论(0编辑  收藏  举报