mirror of
https://github.com/dromara/payment-spring-boot.git
synced 2026-03-14 05:43:46 +08:00
fix: JCE不兼容
- 修复JCE不兼容的问题
This commit is contained in:
@@ -87,9 +87,9 @@ public class SignatureProvider {
|
|||||||
*/
|
*/
|
||||||
private static final Map<String, Certificate> CERTIFICATE_MAP = new ConcurrentHashMap<>();
|
private static final Map<String, Certificate> CERTIFICATE_MAP = new ConcurrentHashMap<>();
|
||||||
/**
|
/**
|
||||||
* 加密算法提供方
|
* 加密算法提供方 - BouncyCastle
|
||||||
*/
|
*/
|
||||||
private static final Provider PROVIDER = new BouncyCastleProvider();
|
private static final String BC_PROVIDER = "BC";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,6 +107,8 @@ public class SignatureProvider {
|
|||||||
* @param wechatMetaContainer the wechat meta container
|
* @param wechatMetaContainer the wechat meta container
|
||||||
*/
|
*/
|
||||||
public SignatureProvider(WechatMetaContainer wechatMetaContainer) {
|
public SignatureProvider(WechatMetaContainer wechatMetaContainer) {
|
||||||
|
Provider bouncyCastleProvider = new BouncyCastleProvider();
|
||||||
|
Security.addProvider(bouncyCastleProvider);
|
||||||
this.wechatMetaContainer = wechatMetaContainer;
|
this.wechatMetaContainer = wechatMetaContainer;
|
||||||
wechatMetaContainer.getTenantIds().forEach(this::refreshCertificate);
|
wechatMetaContainer.getTenantIds().forEach(this::refreshCertificate);
|
||||||
}
|
}
|
||||||
@@ -151,7 +153,7 @@ public class SignatureProvider {
|
|||||||
*/
|
*/
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public String doRequestSign(PrivateKey privateKey, String... orderedComponents) {
|
public String doRequestSign(PrivateKey privateKey, String... orderedComponents) {
|
||||||
Signature signer = Signature.getInstance("SHA256withRSA");
|
Signature signer = Signature.getInstance("SHA256withRSA",BC_PROVIDER);
|
||||||
signer.initSign(privateKey);
|
signer.initSign(privateKey);
|
||||||
final String signatureStr = createSign(orderedComponents);
|
final String signatureStr = createSign(orderedComponents);
|
||||||
signer.update(signatureStr.getBytes(StandardCharsets.UTF_8));
|
signer.update(signatureStr.getBytes(StandardCharsets.UTF_8));
|
||||||
@@ -250,7 +252,7 @@ public class SignatureProvider {
|
|||||||
*/
|
*/
|
||||||
public String decryptResponseBody(String tenantId, String associatedData, String nonce, String ciphertext) {
|
public String decryptResponseBody(String tenantId, String associatedData, String nonce, String ciphertext) {
|
||||||
try {
|
try {
|
||||||
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", PROVIDER);
|
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", BC_PROVIDER);
|
||||||
String apiV3Key = wechatMetaContainer.getWechatMeta(tenantId).getV3().getAppV3Secret();
|
String apiV3Key = wechatMetaContainer.getWechatMeta(tenantId).getV3().getAppV3Secret();
|
||||||
SecretKeySpec key = new SecretKeySpec(apiV3Key.getBytes(StandardCharsets.UTF_8), "AES");
|
SecretKeySpec key = new SecretKeySpec(apiV3Key.getBytes(StandardCharsets.UTF_8), "AES");
|
||||||
GCMParameterSpec spec = new GCMParameterSpec(128, nonce.getBytes(StandardCharsets.UTF_8));
|
GCMParameterSpec spec = new GCMParameterSpec(128, nonce.getBytes(StandardCharsets.UTF_8));
|
||||||
@@ -265,8 +267,7 @@ public class SignatureProvider {
|
|||||||
throw new PayException(e);
|
throw new PayException(e);
|
||||||
}
|
}
|
||||||
return new String(bytes, StandardCharsets.UTF_8);
|
return new String(bytes, StandardCharsets.UTF_8);
|
||||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException |
|
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
|
||||||
InvalidKeyException | InvalidAlgorithmParameterException e) {
|
|
||||||
throw new PayException(e);
|
throw new PayException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
pom.xml
4
pom.xml
@@ -193,7 +193,7 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
<plugins>
|
<plugins>
|
||||||
<!-- <plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
@@ -208,7 +208,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.sonatype.plugins</groupId>
|
<groupId>org.sonatype.plugins</groupId>
|
||||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||||
</plugin>-->
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
Reference in New Issue
Block a user