Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8319937

KeyFactory.generatePublic throws if spec decoded from input with extra bytes

    XMLWordPrintable

Details

    • b24
    • 21
    • generic
    • generic

    Description

      A DESCRIPTION OF THE PROBLEM :
      The attached code works on all Java versions except 21

      REGRESSION : Last worked in version 17.0.9

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      x.509
      ACTUAL -
      unable to decode, extra data

      ---------- BEGIN SOURCE ----------
      import java.security.*;
      import java.security.spec.InvalidKeySpecException;
      import java.security.spec.X509EncodedKeySpec;
      import java.util.Base64;

      public class PublicKeyTester {

          public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeySpecException {
              String keyString = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkN6m/iR+PREcXJfFCaqoohUuteSau4NISwfXXl3yts3C424GuKUS6+3LDJ96xvVMolPBe8haurs1ms1miIq/8CdGlcrAw4FjPCBTZNHdpRA/R75K5crahTieSZalj+ccpOuS9CJujKs8/PLcJeOsXMeOon5XV5Z9laI1tJk8Z9ULPdqxCaHbEWI9RdMGEU8rTlILZSA1+bbh/hLUA6x/BlCAu8wO+Q+e1eWACRkLouCNP67C9xJlfKlzibUnjFOSdmsaJtZgh5BEWkTQeaMO6o6DUhjIwrnVCjfk9O+RcoGYMi6VmpNcAtCFGTB38APpTsu39Sm6MzngNw2fy2AcmwIDAQAB+33pFTKFkH7p2hxZAnUZb5Ji4Uk6RldhsNQJzugoEpJLzkveRTsor+AmrdAiRDY7bNLatnvZnhtrlaCnyT/qGebaYMaXVg88Zb/XlCcAU+NkrXvqF0EvTFqnW46k2tLhFPJS6sKnwkSUTPGWWeBb5j6TPAXR0Ral5g9PHnbAhvyVawVmy9M7NIpVf9OZy9PjQIDAQAB";
              byte[] keyBytes = Base64.getDecoder().decode(keyString);
              X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
              KeyFactory keyFactory = KeyFactory.getInstance("RSA");
              PublicKey publicKey = keyFactory.generatePublic(spec);
              System.out.println(publicKey.getFormat());
          }
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              mpowers Mark Powers
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: