@ 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 .