Skip to content

Commit 7602165

Browse files
committed
Fix type + improve error message
1 parent f73c58a commit 7602165

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

services/cloudfront/src/main/java/software/amazon/awssdk/services/cloudfront/CloudFrontUtilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ private static byte[] signPolicy(byte[] policyToSign, PrivateKey privateKey) thr
495495
// do not attempt to use a generic Signer based on the privateKey algorithm:
496496
// future supported key types likely require different hash algorithms (eg, SHA256 or higher instead of SHA1)
497497
throw new IllegalArgumentException(
498-
"Unsupported key algorithm for for CloudFront signed URL: " + privateKey.getAlgorithm());
498+
"Unsupported key algorithm for CloudFront signed URL: " + privateKey.getAlgorithm());
499499
}
500500
}
501501

services/cloudfront/src/main/java/software/amazon/awssdk/services/cloudfront/internal/utils/SigningUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,14 @@ public static PrivateKey loadPrivateKey(Path keyFile) throws Exception {
226226
/**
227227
* Attempt to load a private key from PKCS8 DER
228228
*/
229-
public static PrivateKey privateKeyFromPkcs8(byte[] derBytes) throws InvalidKeySpecException {
229+
public static PrivateKey privateKeyFromPkcs8(byte[] derBytes) {
230230
EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(derBytes);
231231
try {
232232
return tryKeyLoadFromSpec(privateKeySpec);
233233
} catch (NoSuchAlgorithmException e) {
234234
throw new IllegalArgumentException(e);
235+
} catch (InvalidKeySpecException e) {
236+
throw new IllegalArgumentException("Invalid private key, unable to load as either RSA or ECDSA", e);
235237
}
236238
}
237239

0 commit comments

Comments
 (0)