OpenSSLKey: unsupported algorithm is an InvalidKeyException

When an invalid key is passed in we may throw NoSuchAlgorithmException
if it's a key we don't support, but we should convert this to the
correct exception for this API.

(cherry picked from commit ed396e937f8e0ef878cb9a8d16cff2e5a07f8c7d)

Bug: 21209493
Change-Id: I55123035295203f2676538ac89ba4eb91141b273
diff --git a/src/main/java/org/conscrypt/OpenSSLKey.java b/src/main/java/org/conscrypt/OpenSSLKey.java
index c4c7928..123726a 100644
--- a/src/main/java/org/conscrypt/OpenSSLKey.java
+++ b/src/main/java/org/conscrypt/OpenSSLKey.java
@@ -221,7 +221,11 @@
             throw new InvalidKeyException("Key encoding is null");
         }
 
-        return new OpenSSLKey(NativeCrypto.d2i_PUBKEY(key.getEncoded()));
+        try {
+            return new OpenSSLKey(NativeCrypto.d2i_PUBKEY(key.getEncoded()));
+        } catch (Exception e) {
+            throw new InvalidKeyException(e);
+        }
     }
 
     public PublicKey getPublicKey() throws NoSuchAlgorithmException {