Springboot读取秘钥文件

涉及支付需要在资源文件下resource下放置秘钥,java代码里读取

首先在pom文件里配置以下配置,不然在不会编译在class包里


    org.apache.maven.plugins
    maven-resources-plugin
    UTF-8
        
        
            cer
            pem
            pfx
        
    

java读取方式:

public static InputStream getInputStreamtByPath(String enterpriseCerFilePath) throws IOException {
   try{
      InputStream stream = BhRSAUtil.class.getClassLoader().getResourceAsStream(enterpriseCerFilePath);
      return stream;
   }catch(Exception ioe){
      throw ioe;
   }
}

public static InputStream getSignCertByJarFile2(String enterpriseCerFilePath) throws IOException {
   try{
      ClassPathResource ClassPathResource = new ClassPathResource(enterpriseCerFilePath);
      return ClassPathResource.getInputStream();
   }catch(IOException ioe){
      ioe.printStackTrace();
      throw ioe;
   }
}

 

你可能感兴趣的:(JAVA)