< prev index next >

test/jdk/java/security/KeyRep/Serial.java

Print this page
rev 59383 : [mq]: final
   1 /*
   2  * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  71         kpg.initialize(512);
  72         KeyPair rsaKp = kpg.genKeyPair();
  73 
  74         // serialize RSA key pair
  75         baos.reset();
  76         oos = new ObjectOutputStream(baos);
  77         oos.writeObject(rsaKp);
  78         oos.close();
  79 
  80         // deserialize RSA key pair
  81         ois = new ObjectInputStream
  82                         (new ByteArrayInputStream(baos.toByteArray()));
  83         KeyPair rsaKp2 = (KeyPair)ois.readObject();
  84         ois.close();
  85 
  86         if (!rsaKp2.getPublic().equals(rsaKp.getPublic()) ||
  87             !rsaKp2.getPrivate().equals(rsaKp.getPrivate())) {
  88             throw new SecurityException("RSA test failed");
  89         }
  90 
  91         // exclude test is ECF provider is installed, see 4923290
  92         if (Security.getProvider("SunPKCS11-Solaris") == null) {
  93             // generate DH key pair
  94             kpg = KeyPairGenerator.getInstance("DiffieHellman", JCE);
  95             kpg.initialize(new DHParameterSpec(skip1024Modulus, skip1024Base));
  96             KeyPair dhKp = kpg.genKeyPair();
  97 
  98             // serialize DH key pair
  99             baos.reset();
 100             oos = new ObjectOutputStream(baos);
 101             oos.writeObject(dhKp);
 102             oos.close();
 103 
 104             // deserialize DH key pair
 105             ois = new ObjectInputStream
 106                             (new ByteArrayInputStream(baos.toByteArray()));
 107             KeyPair dhKp2 = (KeyPair)ois.readObject();
 108             ois.close();
 109 
 110             if (!dhKp2.getPublic().equals(dhKp.getPublic()) ||
 111                 !dhKp2.getPrivate().equals(dhKp.getPrivate())) {
 112                 throw new SecurityException("DH test failed");
 113             }
 114         }
 115 
 116         // generate RC5 key
 117         SecretKeySpec rc5Key = new SecretKeySpec(new byte[128], "RC5");
 118 
 119         // serialize RC5 key
 120         baos.reset();
 121         oos = new ObjectOutputStream(baos);
 122         oos.writeObject(rc5Key);
 123         oos.close();
 124 
 125         // deserialize RC5 key
 126         ois = new ObjectInputStream
 127                         (new ByteArrayInputStream(baos.toByteArray()));
 128         SecretKey rc5Key2 = (SecretKey)ois.readObject();
 129         ois.close();
 130 
 131         if (!rc5Key.equals(rc5Key2)) {
 132             throw new SecurityException("RC5 test failed");
 133         }


   1 /*
   2  * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  71         kpg.initialize(512);
  72         KeyPair rsaKp = kpg.genKeyPair();
  73 
  74         // serialize RSA key pair
  75         baos.reset();
  76         oos = new ObjectOutputStream(baos);
  77         oos.writeObject(rsaKp);
  78         oos.close();
  79 
  80         // deserialize RSA key pair
  81         ois = new ObjectInputStream
  82                         (new ByteArrayInputStream(baos.toByteArray()));
  83         KeyPair rsaKp2 = (KeyPair)ois.readObject();
  84         ois.close();
  85 
  86         if (!rsaKp2.getPublic().equals(rsaKp.getPublic()) ||
  87             !rsaKp2.getPrivate().equals(rsaKp.getPrivate())) {
  88             throw new SecurityException("RSA test failed");
  89         }
  90 


  91         // generate DH key pair
  92         kpg = KeyPairGenerator.getInstance("DiffieHellman", JCE);
  93         kpg.initialize(new DHParameterSpec(skip1024Modulus, skip1024Base));
  94         KeyPair dhKp = kpg.genKeyPair();
  95 
  96         // serialize DH key pair
  97         baos.reset();
  98         oos = new ObjectOutputStream(baos);
  99         oos.writeObject(dhKp);
 100         oos.close();
 101 
 102         // deserialize DH key pair
 103         ois = new ObjectInputStream
 104                         (new ByteArrayInputStream(baos.toByteArray()));
 105         KeyPair dhKp2 = (KeyPair)ois.readObject();
 106         ois.close();
 107 
 108         if (!dhKp2.getPublic().equals(dhKp.getPublic()) ||
 109             !dhKp2.getPrivate().equals(dhKp.getPrivate())) {
 110             throw new SecurityException("DH test failed");

 111         }
 112 
 113         // generate RC5 key
 114         SecretKeySpec rc5Key = new SecretKeySpec(new byte[128], "RC5");
 115 
 116         // serialize RC5 key
 117         baos.reset();
 118         oos = new ObjectOutputStream(baos);
 119         oos.writeObject(rc5Key);
 120         oos.close();
 121 
 122         // deserialize RC5 key
 123         ois = new ObjectInputStream
 124                         (new ByteArrayInputStream(baos.toByteArray()));
 125         SecretKey rc5Key2 = (SecretKey)ois.readObject();
 126         ois.close();
 127 
 128         if (!rc5Key.equals(rc5Key2)) {
 129             throw new SecurityException("RC5 test failed");
 130         }


< prev index next >