0N/A/*
5360N/A * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
5360N/A * @bug 0000000 7055362
0N/A * @summary Sealtest
0N/A * @author Jan Luehe
0N/A */
0N/Aimport java.io.*;
0N/Aimport java.security.*;
0N/Aimport javax.crypto.*;
0N/A
0N/Apublic class Sealtest {
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A
0N/A Security.addProvider(new com.sun.crypto.provider.SunJCE());
0N/A
0N/A // create DSA keypair
0N/A KeyPairGenerator kpgen = KeyPairGenerator.getInstance("DSA");
0N/A kpgen.initialize(512);
0N/A KeyPair kp = kpgen.generateKeyPair();
0N/A
0N/A // create DES key
0N/A KeyGenerator kg = KeyGenerator.getInstance("DES");
0N/A SecretKey skey = kg.generateKey();
0N/A
0N/A // create cipher
0N/A Cipher c = Cipher.getInstance("DES/CFB16/PKCS5Padding");
0N/A c.init(Cipher.ENCRYPT_MODE, skey);
0N/A
0N/A // seal the DSA private key
0N/A SealedObject sealed = new SealedObject(kp.getPrivate(), c);
0N/A
0N/A // serialize
5360N/A try (FileOutputStream fos = new FileOutputStream("sealed");
5360N/A ObjectOutputStream oos = new ObjectOutputStream(fos)) {
5360N/A oos.writeObject(sealed);
5360N/A }
0N/A
0N/A // deserialize
5360N/A try (FileInputStream fis = new FileInputStream("sealed");
5360N/A ObjectInputStream ois = new ObjectInputStream(fis)) {
5360N/A sealed = (SealedObject)ois.readObject();
5360N/A }
0N/A
0N/A System.out.println(sealed.getAlgorithm());
0N/A
0N/A // compare unsealed private key with original
0N/A PrivateKey priv = (PrivateKey)sealed.getObject(skey);
0N/A if (!priv.equals(kp.getPrivate()))
0N/A throw new Exception("TEST FAILED");
0N/A
0N/A System.out.println("TEST SUCCEEDED");
0N/A }
0N/A}