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

javax.crypto.EncryptedPrivateKeyInfo.getAlgName returns unexpected data

XMLWordPrintable



      Name: mtR10145 Date: 10/09/2003

      The test code below illustrates that
      javax.crypto.EncryptedPrivateKeyInfo.getAlgName() method returns
      unexpected String (tested with j2se 1.5.0-beta-b22):
      =============================== Test2.java ======================
      import javax.crypto.EncryptedPrivateKeyInfo;
      import java.security.NoSuchAlgorithmException;

      public class Test2 {

          public static void main( String argv[] ) {
              byte [] encryptedData = { 1, 2, 3, 4};
          
              String [] allAlgorithms = {
                  "MD2", "MD5", "SHA-1", "SHA-256",
                  "SHA-384", "SHA-512", "DSA", "RSA",
                  "MD2withRSA", "MD5withRSA", "SHA1withDSA",
                  "SHA1withRSA", "SHA1PRNG" };
          
              String allowedAlgorithm = null;
          
              for (int i = 0; i < allAlgorithms.length; i++) {
                  try {
                      allowedAlgorithm = allAlgorithms[i];
                      EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(allowedAlgorithm, encryptedData);
                      if (!epki.getAlgName().equalsIgnoreCase(allowedAlgorithm))
                          System.out.println("Error: getAlgName returned " + epki.getAlgName() + " when " +
                                              allowedAlgorithm + " expected");
                  } catch (NoSuchAlgorithmException nsae) {
                  }
              }
          }
      }
      =============== Test output ==========================
      Error: getAlgName returned SHA when SHA-1 expected
      ======================================================
      Since several different SHA-based algorithms are available (such as
      SHA-1, SHA-256, SHA-384, SHA-512), getAlgName should return exact name
      of algorithm which was passed to constructor.
      ======================================================================

            valeriep Valerie Peng
            cmssunw Cms Cms (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: