Example usage for com.amazonaws.auth RSA privateKeyFromPKCS8

List of usage examples for com.amazonaws.auth RSA privateKeyFromPKCS8

Introduction

In this page you can find the example usage for com.amazonaws.auth RSA privateKeyFromPKCS8.

Prototype

public static PrivateKey privateKeyFromPKCS8(byte[] pkcs8) throws InvalidKeySpecException 

Source Link

Document

Returns a private key constructed from the given DER bytes in PKCS#8 format.

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;
    }// w  w w  .  j  a  v  a2  s  .  com

    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");
    }
}