创建AWS Cloudfront自签名URL(java SDK)时出错

时间:2019-06-24 21:09:49

标签: java amazon-web-services amazon-cloudfront

我正在尝试使用AWS Cloudfront创建自签名的url。这是我的代码:

public class SignedUrl {

public void generateSignedUrl(String objectKey) throws IOException {
    // the DNS name of your CloudFront distribution, or a registered alias
    String distributionDomainName = "mydomain";
    // the private key you created in the AWS Management Console
    File cloudFrontPrivateKeyFile = new File(".");
    File[] matchingFiles = cloudFrontPrivateKeyFile.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".pem");
        }
    });
    System.out.println(matchingFiles[0].getCanonicalPath());
    String cloudFrontKeyPairId = "mykey";
    Date expirationDate = new Date(System.currentTimeMillis() + 60 * 1000);
    try {
        String signedUrl = CloudFrontUrlSigner.getSignedURLWithCannedPolicy(
                SignerUtils.Protocol.https,
                distributionDomainName,
                cloudFrontPrivateKeyFile,
                objectKey,
                cloudFrontKeyPairId,
                expirationDate);

    } catch (InvalidKeySpecException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

}

我跟随着这些示例的AWS教程,创建了Cloudfront公钥和私钥,但出现错误:

com.amazonaws.AmazonClientException:私钥不支持的文件类型

有人知道如何解决这个问题吗?我试图转换为.der文件(我在旧的AWS文档中阅读了),但仍然无法正常工作。

0 个答案:

没有答案