🎨 【微信支付】修复证书私钥问题

This commit is contained in:
zhoujiangzi2010 2024-03-29 11:25:43 +00:00 committed by Binary Wang
parent 2e3865fd21
commit fe5430ee65
2 changed files with 28 additions and 0 deletions

View File

@ -263,6 +263,9 @@ public class WxPayConfig {
throw new WxPayException("请确保apiV3Key值已设置");
}
if(StringUtils.isNotBlank(this.getPrivateKeyString())){
this.setPrivateKeyString(Base64.getEncoder().encodeToString(this.getPrivateKeyString().getBytes()));
}
InputStream keyInputStream = this.loadConfigInputStream(this.getPrivateKeyString(), this.getPrivateKeyPath(),
this.privateKeyContent, "privateKeyPath");
try {

View File

@ -1,7 +1,16 @@
package com.github.binarywang.wxpay.config;
import com.github.binarywang.wxpay.exception.WxPayException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.pqc.jcajce.provider.util.KeyUtil;
import org.testng.annotations.Test;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Security;
import java.util.Base64;
/**
* <pre>
* Created by BinaryWang on 2017/6/18.
@ -44,4 +53,20 @@ public class WxPayConfigTest {
payConfig.setKeyString("MIIKmgIBAzCCCmQGCS...");
payConfig.initSSLContext();
}
@Test
public void testInitApiV3HttpClient() throws Exception {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA","BC");
keyPairGenerator.initialize(2048,new SecureRandom());
KeyPair keyPair = keyPairGenerator.genKeyPair();
byte[] encoded = keyPair.getPrivate().getEncoded();
// 模拟用户配置
String privateKeyString = Base64.getEncoder().encodeToString(encoded);
payConfig.setPrivateKeyString(privateKeyString);
payConfig.setApiV3Key("Test");
payConfig.initApiV3HttpClient();
}
}