content: package com.aliyun.gmsse;
  
  import java.io.BufferedReader;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.nio.charset.StandardCharsets;
  import java.security.KeyFactory;
  import java.security.KeyStoreException;
  import java.security.NoSuchAlgorithmException;
  import java.security.PrivateKey;
  import java.security.cert.CertificateException;
  import java.security.cert.CertificateFactory;
  import java.security.cert.X509Certificate;
  import java.security.spec.InvalidKeySpecException;
  import java.security.spec.PKCS8EncodedKeySpec;
  import java.util.Base64;
  
  import org.bouncycastle.jce.provider.BouncyCastleProvider;
  
  public class Helper {
      public static X509Certificate loadCertificate(String path) throws KeyStoreException, CertificateException, FileNotFoundException {
          BouncyCastleProvider bc = new BouncyCastleProvider();
          CertificateFactory cf = CertificateFactory.getInstance("X.509", bc);
          InputStream is = Helper.class.getClassLoader().getResourceAsStream(path);
          X509Certificate cert = (X509Certificate) cf.generateCertificate(is);
          return cert;
      }
  
      public static PrivateKey loadPrivateKey(String path) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
          InputStream is = Helper.class.getClassLoader().getResourceAsStream(path);
          InputStreamReader inputStreamReader = new InputStreamReader(is);
          BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
          StringBuilder sb = new StringBuilder();
          String line = null;
              while ((line = bufferedReader.readLine()) != null){
              if (line.startsWith("-")){
                  continue;
              }
              sb.append(line).append("\n");
          }
          String ecKey = sb.toString().replaceAll("\\r\\n|\\r|\\n", "");
          Base64.Decoder base64Decoder = Base64.getDecoder();
          byte[] keyByte = base64Decoder.decode(ecKey.getBytes(StandardCharsets.UTF_8));
          PKCS8EncodedKeySpec eks2 = new PKCS8EncodedKeySpec(keyByte);
          KeyFactory keyFactory = KeyFactory.getInstance("EC", new BouncyCastleProvider());
          PrivateKey privateKey = keyFactory.generatePrivate(eks2);
          return privateKey;
      }
  }
  