From 9096b7958ea1c25005e56db879a4e723d1d6ed89 Mon Sep 17 00:00:00 2001 From: jeanwu <513564656@qq.com> Date: Mon, 6 May 2024 18:07:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E6=BB=9A=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractNotificationConfig.java | 23 ------------ .../notification/RSANotificationConfig.java | 37 ------------------- 2 files changed, 60 deletions(-) diff --git a/core/src/main/java/com/wechat/pay/java/core/notification/AbstractNotificationConfig.java b/core/src/main/java/com/wechat/pay/java/core/notification/AbstractNotificationConfig.java index b2c417a6..edc764f8 100644 --- a/core/src/main/java/com/wechat/pay/java/core/notification/AbstractNotificationConfig.java +++ b/core/src/main/java/com/wechat/pay/java/core/notification/AbstractNotificationConfig.java @@ -4,7 +4,6 @@ import com.wechat.pay.java.core.cipher.AeadCipher; import com.wechat.pay.java.core.cipher.RSAVerifier; import com.wechat.pay.java.core.cipher.Verifier; -import java.security.PublicKey; public abstract class AbstractNotificationConfig implements NotificationConfig { @@ -13,9 +12,6 @@ public abstract class AbstractNotificationConfig implements NotificationConfig { private final CertificateProvider certificateProvider; private final AeadCipher aeadCipher; - private final PublicKey publicKey; - private final String publicKeyId; - protected AbstractNotificationConfig( String signType, String cipherAlgorithm, @@ -25,22 +21,6 @@ protected AbstractNotificationConfig( this.cipherAlgorithm = cipherAlgorithm; this.certificateProvider = certificateProvider; this.aeadCipher = aeadCipher; - this.publicKey = null; - this.publicKeyId = null; - } - - protected AbstractNotificationConfig( - String signType, - String cipherAlgorithm, - PublicKey publicKey, - String publicKeyId, - AeadCipher aeadCipher) { - this.signType = signType; - this.cipherAlgorithm = cipherAlgorithm; - this.publicKey = publicKey; - this.publicKeyId = publicKeyId; - this.aeadCipher = aeadCipher; - this.certificateProvider = null; } @Override @@ -55,9 +35,6 @@ public String getCipherType() { @Override public Verifier createVerifier() { - if (publicKey != null) { - return new RSAVerifier(publicKey, publicKeyId); - } return new RSAVerifier(certificateProvider); } diff --git a/core/src/main/java/com/wechat/pay/java/core/notification/RSANotificationConfig.java b/core/src/main/java/com/wechat/pay/java/core/notification/RSANotificationConfig.java index 930c1c11..1627b4d0 100644 --- a/core/src/main/java/com/wechat/pay/java/core/notification/RSANotificationConfig.java +++ b/core/src/main/java/com/wechat/pay/java/core/notification/RSANotificationConfig.java @@ -8,10 +8,8 @@ import com.wechat.pay.java.core.certificate.InMemoryCertificateProvider; import com.wechat.pay.java.core.cipher.AeadAesCipher; import com.wechat.pay.java.core.cipher.AeadCipher; -import com.wechat.pay.java.core.exception.ValidationException; import com.wechat.pay.java.core.util.PemUtil; import java.nio.charset.StandardCharsets; -import java.security.PublicKey; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; @@ -24,18 +22,11 @@ private RSANotificationConfig(CertificateProvider certificateProvider, AeadCiphe super(RSA_SIGN_TYPE, AES_CIPHER_ALGORITHM, certificateProvider, aeadCipher); } - private RSANotificationConfig(PublicKey publicKey, String publicKeyId, AeadCipher aeadCipher) { - super(RSA_SIGN_TYPE, AES_CIPHER_ALGORITHM, publicKey, publicKeyId, aeadCipher); - } - public static class Builder { private List certificates; private byte[] apiV3Key; - private PublicKey publicKey; - private String publicKeyId; - public Builder certificates(X509Certificate... certificates) { this.certificates = Arrays.asList(certificates); return this; @@ -61,40 +52,12 @@ public Builder certificatesFromPath(String... certificatePaths) { return this; } - public Builder publicKey(String publicKey) { - this.publicKey = PemUtil.loadPublicKeyFromString(publicKey); - return this; - } - - public Builder publicKey(PublicKey publicKey) { - this.publicKey = publicKey; - return this; - } - - public Builder publicFromPath(String publicKeyPath) { - this.publicKey = PemUtil.loadPublicKeyFromPath(publicKeyPath); - return this; - } - public Builder apiV3Key(String apiV3Key) { this.apiV3Key = apiV3Key.getBytes(StandardCharsets.UTF_8); return this; } - public Builder publicKeyId(String publicKeyId) { - this.publicKeyId = publicKeyId; - return this; - } - public RSANotificationConfig build() { - if (publicKey != null && certificates != null) { - throw new ValidationException( - "only one parameter can be set between publicKey and certificates"); - } - if (publicKey != null) { - return new RSANotificationConfig( - publicKey, requireNonNull(publicKeyId), new AeadAesCipher(requireNonNull(apiV3Key))); - } CertificateProvider certificateProvider = new InMemoryCertificateProvider(certificates); return new RSANotificationConfig( certificateProvider, new AeadAesCipher(requireNonNull(apiV3Key)));