HeliPayCertConfig.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.caimei.modules.order.utils;
  2. import org.bouncycastle.jce.provider.BouncyCastleProvider;
  3. import java.security.PrivateKey;
  4. import java.security.PublicKey;
  5. import java.security.Security;
  6. public class HeliPayCertConfig {
  7. /**
  8. * 证书存储路径
  9. */
  10. private static final String CERT_PATH = "key\\dev\\";
  11. //private static final String CERT_PATH = "D:\\certs\\key\\dev\\";
  12. /**
  13. * 商户SM2证书私钥路径
  14. */
  15. private static final String MERCHANT_PRIVATE_KEY_PATH = CERT_PATH + "C1800000002_dev.pfx";
  16. /**
  17. * 商户SM2证书私钥密码
  18. */
  19. private static final String MERCHANT_PRIVATE_KEY_PWD = "123456";
  20. /**
  21. * 商户SM2证书私钥字符串
  22. */
  23. private static final PrivateKey merchantPrivateKey;
  24. /**
  25. * 合利宝SM2证书公钥路径
  26. */
  27. private static final String HELIPAY_PUBLIC_KEY_PATH = CERT_PATH + "helipay_pub_dev.cer";//取决支付系统加载的合利宝私钥配对
  28. //加密机公钥证书
  29. //private static final String HELIPAY_PUBLIC_KEY_PATH = "D:\\certs\\hsm\\helipay-hsm.cer";
  30. /**
  31. * 合利宝SM2证书公钥对象
  32. */
  33. private static final PublicKey helipayPublicKey;
  34. static {
  35. if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
  36. Security.addProvider(new BouncyCastleProvider());
  37. }
  38. try {
  39. merchantPrivateKey = HeliPayCertUtils.getPrivateKeyByPfx("/mnt/newdatadrive/keys/C1806995267_2303010060964109_privateKey.pfx","cm20230327");
  40. } catch (Exception e) {
  41. throw new RuntimeException("获取SM2证书私钥字符串异常:"+e.getMessage(),e) ;
  42. }
  43. try {
  44. helipayPublicKey = HeliPayCertUtils.getPublicKey("/mnt/newdatadrive/keys/helipayPublicKey.cer");
  45. } catch (Exception e) {
  46. throw new RuntimeException("加载合利宝SM2证书公钥异常异常:"+e.getMessage(),e) ;
  47. }
  48. }
  49. public static PrivateKey getMerchantPrivateKey() {
  50. return merchantPrivateKey;
  51. }
  52. public static PublicKey getHelipayPublicKey() {
  53. return helipayPublicKey;
  54. }
  55. }