0N/A/*
2362N/A * Copyright (c) 1998, 2007, 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
0N/A * @bug 0000000
0N/A * @summary FlushBug
0N/A * @author Jan Luehe
0N/A */
0N/Aimport java.io.*;
0N/Aimport java.security.*;
0N/Aimport javax.crypto.*;
0N/Aimport javax.crypto.spec.*;
0N/Aimport com.sun.crypto.provider.SunJCE;
0N/A
0N/Apublic class FlushBug {
0N/A public static void main(String[] args) throws Exception {
0N/A
0N/A Provider prov = new com.sun.crypto.provider.SunJCE();
0N/A Security.addProvider(prov);
0N/A
0N/A SecureRandom sr = new SecureRandom();
0N/A
0N/A // Create new DES key.
0N/A KeyGenerator kg = KeyGenerator.getInstance("DES");
0N/A kg.init(sr);
0N/A Key key = kg.generateKey();
0N/A
0N/A // Generate an IV.
0N/A byte[] iv_bytes = new byte[8];
0N/A sr.nextBytes(iv_bytes);
0N/A IvParameterSpec iv = new IvParameterSpec(iv_bytes);
0N/A
0N/A // Create the consumer
0N/A Cipher decrypter = Cipher.getInstance("DES/CFB8/NoPadding");
0N/A decrypter.init(Cipher.DECRYPT_MODE, key, iv);
0N/A PipedInputStream consumer = new PipedInputStream();
0N/A InputStream in = new CipherInputStream(consumer, decrypter);
0N/A
0N/A // Create the producer
0N/A Cipher encrypter = Cipher.getInstance("DES/CFB8/NoPadding");
0N/A encrypter.init(Cipher.ENCRYPT_MODE, key, iv);
0N/A PipedOutputStream producer = new PipedOutputStream();
0N/A OutputStream out = new CipherOutputStream(producer, encrypter);
0N/A
0N/A producer.connect(consumer); // connect pipe
0N/A
0N/A byte[] plaintext = "abcdef".getBytes();
0N/A for (int i = 0; i < plaintext.length; i++) {
0N/A out.write(plaintext[i]);
0N/A out.flush();
0N/A int b = in.read();
0N/A String original = new String(plaintext, i, 1);
0N/A String result = new String(new byte[] { (byte)b });
0N/A System.out.println(" " + original + " -> " + result);
0N/A }
0N/A }
0N/A}