private PrivateKey getPemPrivateKey ( final String keyString ) throws EncryptionException { try { final String privKeyPEM = keyString . replace ( "-----BEGIN PRIVATE KEY-----" , "" ) . replace ( "-----END PRIVATE KEY-----" , "" ) . replaceAll ( "\\v" , "" ) ; final Base64 b64 = new Base64 ( ) ; final byte [ ] decoded = b64 . decode ( privKeyPEM ) ; final PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec ( decoded ) ; final KeyFactory kf = KeyFactory . getInstance ( ALGORITHM ) ; return kf . generatePrivate ( spec ) ; } catch ( NoSuchAlgorithmException | InvalidKeySpecException e ) { throw new EncryptionException ( "Unable to obtain private key: " , e ) ; } }
Initializes a private key from a string .