weizhouapache commented on code in PR #14317:
URL: https://github.com/apache/cloudstack/pull/14317#discussion_r4194820653


##########
utils/src/main/java/com/cloud/utils/security/CertificateHelper.java:
##########
@@ -133,9 +135,16 @@ public static Certificate buildCertificate(final String 
content) throws Certific
     public static Key buildPrivateKey(final String base64EncodedKeyContent) 
throws NoSuchAlgorithmException, InvalidKeySpecException, IOException {
         Preconditions.checkNotNull(base64EncodedKeyContent);
 
-        final KeyFactory kf = KeyFactory.getInstance("RSA");
         final PKCS8EncodedKeySpec keysp = new 
PKCS8EncodedKeySpec(Base64.decodeBase64(base64EncodedKeyContent));
-        return kf.generatePrivate(keysp);
+        InvalidKeySpecException lastException = null;
+        for (final String algorithm : PRIVATE_KEY_ALGORITHMS) {
+            try {
+                return 
KeyFactory.getInstance(algorithm).generatePrivate(keysp);
+            } catch (final InvalidKeySpecException e) {
+                lastException = e;
+            }
+        }
+        throw lastException;

Review Comment:
   maybe throw an exception saying that the provided key is not one of 3 
support types



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to