Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/crypto/provider/Cipher/DES/FlushBug.java
41161 views
1
/*
2
* Copyright (c) 1998, 2015, 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
*/
23
24
/*
25
* @test
26
* @bug 0000000
27
* @summary FlushBug
28
* @author Jan Luehe
29
* @key randomness
30
*/
31
import java.io.*;
32
import java.security.*;
33
import javax.crypto.*;
34
import javax.crypto.spec.*;
35
36
public class FlushBug {
37
public static void main(String[] args) throws Exception {
38
SecureRandom sr = new SecureRandom();
39
40
// Create new DES key.
41
KeyGenerator kg = KeyGenerator.getInstance("DES", "SunJCE");
42
kg.init(sr);
43
Key key = kg.generateKey();
44
45
// Generate an IV.
46
byte[] iv_bytes = new byte[8];
47
sr.nextBytes(iv_bytes);
48
IvParameterSpec iv = new IvParameterSpec(iv_bytes);
49
50
// Create the consumer
51
Cipher decrypter = Cipher.getInstance("DES/CFB8/NoPadding", "SunJCE");
52
decrypter.init(Cipher.DECRYPT_MODE, key, iv);
53
PipedInputStream consumer = new PipedInputStream();
54
InputStream in = new CipherInputStream(consumer, decrypter);
55
56
// Create the producer
57
Cipher encrypter = Cipher.getInstance("DES/CFB8/NoPadding", "SunJCE");
58
encrypter.init(Cipher.ENCRYPT_MODE, key, iv);
59
PipedOutputStream producer = new PipedOutputStream();
60
OutputStream out = new CipherOutputStream(producer, encrypter);
61
62
producer.connect(consumer); // connect pipe
63
64
byte[] plaintext = "abcdef".getBytes();
65
for (int i = 0; i < plaintext.length; i++) {
66
out.write(plaintext[i]);
67
out.flush();
68
int b = in.read();
69
String original = new String(plaintext, i, 1);
70
String result = new String(new byte[] { (byte)b });
71
System.out.println(" " + original + " -> " + result);
72
}
73
}
74
}
75
76