private byte[] replaceAndBase64Decode(
final String file, final String headReplace, final String tailReplace) throws Exception {
// 从 classpath:resources/ 中加载资源
final ResourceLoader loader = new DefaultResourceLoader();
final File f = loader.getResource(file).getFile();
final FileInputStream fis = new FileInputStream(f);
final DataInputStream dis = new DataInputStream(fis);
final byte[] keyBytes = new byte[(int) f.length()];
dis.readFully(keyBytes);
dis.close();
final String keyPEM =
new String(keyBytes).replace(headReplace, "").trim().replace(tailReplace, "").trim();
return Base64.decodeBase64(keyPEM);
private byte[] replaceAndBase64Decode(
final String file, final String headReplace, final String tailReplace) throws Exception {
// 从 classpath:resources/ 中加载资源
final ClassPathResource resource = new ClassPathResource(file);
final InputStream fis = resource.getInputStream();
final byte[] keyBytes = IOUtils.toByteArray(fis);
final String keyPEM =
new String(keyBytes).replace(headReplace, "").trim().replace(tailReplace, "").trim();
return Base64.decodeBase64(keyPEM);
}