mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🎨 【微信支付】修复证书私钥问题
This commit is contained in:
parent
2e3865fd21
commit
fe5430ee65
@ -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 {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user