Example usage for com.amazonaws.auth PEM readPrivateKey

List of usage examples for com.amazonaws.auth PEM readPrivateKey

Introduction

In this page you can find the example usage for com.amazonaws.auth PEM readPrivateKey.

Prototype

public static PrivateKey readPrivateKey(InputStream is) throws InvalidKeySpecException, IOException 

Source Link

Document

Returns the first private key that is found from the input stream of a PEM file.

Usage

From source file:org.nuxeo.ecm.core.storage.sql.CloudFrontBinaryManager.java

License:Apache License

private static PrivateKey loadPrivateKey(String privateKeyPath) throws InvalidKeySpecException, IOException {
    if (privateKeyPath == null) {
        return null;
    }/*from   ww w.  j  av  a 2 s.c  o m*/

    try (FileInputStream is = new FileInputStream(new File(privateKeyPath))) {
        if (privateKeyPath.toLowerCase().endsWith(".pem")) {
            return PEM.readPrivateKey(is);
        }

        if (privateKeyPath.toLowerCase().endsWith(".der")) {
            return RSA.privateKeyFromPKCS8(IOUtils.toByteArray(is));
        }

        throw new AmazonClientException("Unsupported file type for private key");
    }
}