SunMSCAPI's Cipher can't use RSA public keys obtained from other sources.

XMLWordPrintable

    • b142
    • generic
    • generic
    • Not verified

      test.p12 is attached. Use IE to import the certificate/private key into the browser's keystore. Password is "test". Then run the following:

          public static void main(String[] arg) throws Exception {
              PrivateKey privKey = null;
              Certificate cert = null;
              KeyStore ks = KeyStore.getInstance("Windows-MY");
              ks.load(null, null);
              PublicKey myPuKey = (PublicKey)
                  ks.getCertificate("test_cert0").getPublicKey();

              Cipher rsa = Cipher.getInstance("RSA/ECB/PKCS1Padding", "SunMSCAPI");
              rsa.init(Cipher.ENCRYPT_MODE, myPuKey);

      myPuKey is a sun.security.rsa.RSAPublicKeyImpl here.

      But MSCAPI checks that:

              if (!(key instanceof sun.security.mscapi.Key)) {
                  throw new InvalidKeyException("Unsupported key type: " + key);
              }

      The current MSCAPI will choke on this in two places with an Unsupported key type. First in engineGetKeySize, and then in the actual Cipher's init routine.

            Assignee:
            Vincent Ryan
            Reporter:
            Bradford Wetmore
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: