test/com/sun/crypto/provider/Cipher/KeyWrap/XMLEncKAT.java

Print this page

        

@@ -24,20 +24,18 @@
 /*
  * @test
  * @bug 5008159 5008156
  * @summary Verify that the two key wrap ciphers, i.e. "DESedeWrap"
  * and "AESWrap", work as expected.
- * @modules java.base/sun.misc
  * @run main XMLEncKAT
  * @author Valerie Peng
  */
+import java.util.Base64;
 import java.security.Key;
 import java.security.AlgorithmParameters;
 import javax.crypto.*;
 import javax.crypto.spec.*;
-import sun.misc.BASE64Decoder;
-import sun.misc.BASE64Encoder;
 import java.io.UnsupportedEncodingException;
 import java.io.IOException;
 
 public class XMLEncKAT {
 

@@ -48,34 +46,32 @@
     private static byte[] desEdeKey_2;
     private static byte[] aes128Key_2;
     private static byte[] aes192Key_2;
     private static byte[] aes256Key_2;
 
-    private static BASE64Decoder base64D = new BASE64Decoder();
-    private static BASE64Encoder base64E = new BASE64Encoder();
+    private static Base64.Decoder base64D = Base64.getDecoder();
+    private static Base64.Encoder base64E = Base64.getEncoder();
 
     static {
         try {
             desEdeKey_1 = "abcdefghijklmnopqrstuvwx".getBytes("ASCII");
             aes128Key_1 = "abcdefghijklmnop".getBytes("ASCII");
             aes192Key_1 = "abcdefghijklmnopqrstuvwx".getBytes("ASCII");
             aes256Key_1 = "abcdefghijklmnopqrstuvwxyz012345".getBytes("ASCII");
         } catch (UnsupportedEncodingException uee) {
             // should never happen
         }
-        try {
-            desEdeKey_2 = base64D.decodeBuffer
+
+        desEdeKey_2 = base64D.decode
                 ("yI+J1f3puYAERjIcT6vfg6RitmKX8nD0");
-            aes128Key_2 = base64D.decodeBuffer
+        aes128Key_2 = base64D.decode
                 ("01+yuQ2huPS1+Qv0LH+zaQ==");
-            aes192Key_2 = base64D.decodeBuffer
+        aes192Key_2 = base64D.decode
                 ("IlfuS40LvStVU0Mj8ePrrGHVhAb48y++");
-            aes256Key_2 = base64D.decodeBuffer
+        aes256Key_2 = base64D.decode
                 ("ZhZ4v3RlwTlCEOpIrHfLKVyJOBDtEJOOQDat/4xR1bA=");
-        } catch (IOException ioe) {
-            // should never happen
-        }
+
     }
     private static String[] desEdeWrappedKey_1 = {
         "ZyJbVsjRM4MEsswwwHz57aUz1eMqZHuEIoEPGS47CcmLvhuCtlzWZ9S/WcVJZIpz",
         "gHMpx5iF7+KXtNHLasZrkcLHn8Ti4rxUjCIRK+IcgbQir6FUsQ/uxQ3o8enEMWq1"
     };

@@ -121,21 +117,21 @@
         Key[] key = new SecretKey[base64Wrapped.length];
         IvParameterSpec[] params =
             new IvParameterSpec[base64Wrapped.length];
         // first test UNWRAP with known values
         for (int i = 0; i < base64Wrapped.length; i++) {
-            byte[] wrappedKey = base64D.decodeBuffer(base64Wrapped[i]);
+            byte[] wrappedKey = base64D.decode(base64Wrapped[i]);
             key[i] = c.unwrap(wrappedKey, "AES", Cipher.SECRET_KEY);
             if (c.getIV() != null) {
                 params[i] = new IvParameterSpec(c.getIV());
             }
         }
         // then test WRAP and compare with the known values
         for (int i = 0; i < key.length; i++) {
             c.init(Cipher.WRAP_MODE, cKey, params[i]);
             byte[] wrapped2 = c.wrap(key[i]);
-            String out = base64E.encode(wrapped2);
+            String out = base64E.encodeToString(wrapped2);
             if (!out.equalsIgnoreCase(base64Wrapped[i])) {
                 throw new Exception("Wrap failed; got " + out + ", expect " +
                                    base64Wrapped[i]);
             }
         }