创建AWS Cloudfront自签名URL(java sdk)时出现amazon web服务错误
我正在尝试使用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。亚马逊。AmazonClientException:不支持私钥的文件类型
有人知道怎么解决这个问题吗?我试着改变信仰。der文件(我读了一份旧的AWS文档),但仍然不起作用
共 (0) 个答案