From 5404c914028a4fee4827209a21d2e843adfcaa05 Mon Sep 17 00:00:00 2001 From: "felord.cn" Date: Sun, 31 Jan 2021 14:08:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20JCE=E4=B8=8D=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复JCE不兼容的问题 --- .../cn/felord/payment/wechat/v3/SignatureProvider.java | 9 ++++++++- pom.xml | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/SignatureProvider.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/SignatureProvider.java index 1397578..204966b 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/SignatureProvider.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/SignatureProvider.java @@ -27,6 +27,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import lombok.SneakyThrows; +import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.springframework.http.*; import org.springframework.util.AlternativeJdkIdGenerator; import org.springframework.util.Base64Utils; @@ -85,6 +86,12 @@ public class SignatureProvider { * 微信平台证书容器 key = 序列号 value = 证书对象 */ private static final Map CERTIFICATE_MAP = new ConcurrentHashMap<>(); + /** + * 加密算法提供方 + */ + private static final Provider PROVIDER = new BouncyCastleProvider(); + + /** * The Rest operations. */ @@ -243,7 +250,7 @@ public class SignatureProvider { */ public String decryptResponseBody(String tenantId, String associatedData, String nonce, String ciphertext) { try { - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", PROVIDER); String apiV3Key = wechatMetaContainer.getWechatMeta(tenantId).getV3().getAppV3Secret(); SecretKeySpec key = new SecretKeySpec(apiV3Key.getBytes(StandardCharsets.UTF_8), "AES"); GCMParameterSpec spec = new GCMParameterSpec(128, nonce.getBytes(StandardCharsets.UTF_8)); diff --git a/pom.xml b/pom.xml index 282b7c4..e8a2b5e 100644 --- a/pom.xml +++ b/pom.xml @@ -193,7 +193,7 @@ - + \ No newline at end of file