src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CSignature.java
changeset 55380 22b3b7983ada
parent 54827 01fa7f06f806
--- a/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CSignature.java	Thu Jun 13 15:24:34 2019 +0100
+++ b/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/CSignature.java	Thu Jun 13 23:53:21 2019 +0800
@@ -118,7 +118,9 @@
         // initialize for signing. See JCA doc
         @Override
         protected void engineInitSign(PrivateKey key) throws InvalidKeyException {
-
+            if (key == null) {
+                throw new InvalidKeyException("Key cannot be null");
+            }
             if ((key instanceof CPrivateKey) == false
                     || !key.getAlgorithm().equalsIgnoreCase("RSA")) {
                 throw new InvalidKeyException("Key type not supported: "
@@ -139,9 +141,13 @@
         // initialize for signing. See JCA doc
         @Override
         protected void engineInitVerify(PublicKey key) throws InvalidKeyException {
+            if (key == null) {
+                throw new InvalidKeyException("Key cannot be null");
+            }
             // This signature accepts only RSAPublicKey
             if ((key instanceof RSAPublicKey) == false) {
-                throw new InvalidKeyException("Key type not supported");
+                throw new InvalidKeyException("Key type not supported: "
+                        + key.getClass());
             }
 
 
@@ -427,9 +433,13 @@
         // initialize for signing. See JCA doc
         @Override
         protected void engineInitSign(PrivateKey key) throws InvalidKeyException {
+            if (key == null) {
+                throw new InvalidKeyException("Key cannot be null");
+            }
             if ((key instanceof CPrivateKey) == false
                     || !key.getAlgorithm().equalsIgnoreCase("EC")) {
-                throw new InvalidKeyException("Key type not supported");
+                throw new InvalidKeyException("Key type not supported: "
+                        + key.getClass() + " " + key.getAlgorithm());
             }
             privateKey = (CPrivateKey) key;
 
@@ -440,12 +450,15 @@
         // initialize for signing. See JCA doc
         @Override
         protected void engineInitVerify(PublicKey key) throws InvalidKeyException {
+            if (key == null) {
+                throw new InvalidKeyException("Key cannot be null");
+            }
             // This signature accepts only ECPublicKey
             if ((key instanceof ECPublicKey) == false) {
-                throw new InvalidKeyException("Key type not supported");
+                throw new InvalidKeyException("Key type not supported: "
+                        + key.getClass());
             }
 
-
             if ((key instanceof CPublicKey) == false) {
                 try {
                     publicKey = importECPublicKey("EC",
@@ -508,9 +521,13 @@
 
         @Override
         protected void engineInitVerify(PublicKey key) throws InvalidKeyException {
+            if (key == null) {
+                throw new InvalidKeyException("Key cannot be null");
+            }
             // This signature accepts only RSAPublicKey
             if ((key instanceof java.security.interfaces.RSAPublicKey) == false) {
-                throw new InvalidKeyException("Key type not supported");
+                throw new InvalidKeyException("Key type not supported: "
+                        + key.getClass());
             }
 
             this.privateKey = null;