1

Could you please suggest alternate class for PEM to read private key. Code is as below:

import com.amazonaws.auth.PEM;

public PrivateKey getPrivateKey(String filename1) throws Exception {                
    InputStream res= new FileInputStream(filename1);              
    PrivateKey key = PEM.readPrivateKey(res);              
    return key;         
}
madhead
  • 31,729
  • 16
  • 153
  • 201
preet kaur
  • 33
  • 3

1 Answers1

0

What about general Java APIs?

public PrivateKey read(String filename) throws Exception {
    final byte[] bytes = Files.readAllBytes(Paths.get(filename));
    final PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(bytes);
    final KeyFactory kf = KeyFactory.getInstance("RSA");

    return kf.generatePrivate(spec);
}
madhead
  • 31,729
  • 16
  • 153
  • 201