refactor: V2 签名优化

This commit is contained in:
felord
2021-08-18 16:34:29 +08:00
parent e38167e748
commit 9eb58860f1

View File

@@ -152,10 +152,11 @@ public abstract class BaseModel {
*/ */
@SneakyThrows @SneakyThrows
private String hmacSha256(String src) { private String hmacSha256(String src) {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); String algorithm = "HmacSHA256";
SecretKeySpec secret_key = new SecretKeySpec(appSecret.getBytes(),"HmacSHA256"); Mac sha256HMAC = Mac.getInstance(algorithm,"BC");
sha256_HMAC.init(secret_key); SecretKeySpec secretKeySpec = new SecretKeySpec(appSecret.getBytes(), algorithm);
byte[] bytes = sha256_HMAC.doFinal(src.getBytes(StandardCharsets.UTF_8)); sha256HMAC.init(secretKeySpec);
byte[] bytes = sha256HMAC.doFinal(src.getBytes(StandardCharsets.UTF_8));
return Hex.toHexString(bytes).toUpperCase(); return Hex.toHexString(bytes).toUpperCase();
} }