@SneakyThrows public RSAPrivateKey loadPrivateKey(String privateKeyLocation){
  Resource keyRes=resourceLoader.getResource(privateKeyLocation);
  byte[] keyBytes=StreamUtils.copyToByteArray(keyRes.getInputStream());
  PKCS8EncodedKeySpec privateKeySpec=new PKCS8EncodedKeySpec(keyBytes);
  KeyFactory keyFactory=KeyFactory.getInstance("RSA");
  RSAPrivateKey privateKey=(RSAPrivateKey)keyFactory.generatePrivate(privateKeySpec);
  return privateKey;
}

@ SneakyThrows public RSAPrivateKey loadPrivateKey ( String privateKeyLocation ) { Resource keyRes = resourceLoader . getResource ( privateKeyLocation ) ; byte [ ] keyBytes = StreamUtils . copyToByteArray ( keyRes . getInputStream ( ) ) ; PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec ( keyBytes ) ; KeyFactory keyFactory = KeyFactory . getInstance ( "RSA" ) ; RSAPrivateKey privateKey = ( RSAPrivateKey ) keyFactory . generatePrivate ( privateKeySpec ) ; return privateKey ; }
given a resource location it loads a der rsa private key .
