Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/crypto/provider/CICO/PBEFunc/CipherNCFuncTest.java
41161 views
1
/*
2
* Copyright (c) 2001, 2017, 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 8048604
27
* @library ../ /test/lib
28
* @build jdk.test.lib.RandomFactory
29
* @run main CipherNCFuncTest
30
* @summary This test verifies the assertion "There should be no transformation
31
* on the plaintext/ciphertext in encryption/decryption mechanism" for
32
* feature "NullCipher".
33
*/
34
35
import javax.crypto.BadPaddingException;
36
import javax.crypto.Cipher;
37
import javax.crypto.IllegalBlockSizeException;
38
import javax.crypto.NullCipher;
39
import javax.crypto.ShortBufferException;
40
import jdk.test.lib.RandomFactory;
41
42
public class CipherNCFuncTest {
43
public static void main(String[] args) throws ShortBufferException,
44
IllegalBlockSizeException, BadPaddingException {
45
byte[] plainText = new byte[801];
46
// Initialization
47
RandomFactory.getRandom().nextBytes(plainText);
48
Cipher ci = new NullCipher();
49
// Encryption
50
byte[] cipherText = new byte[ci.getOutputSize(plainText.length)];
51
int offset = ci.update(plainText, 0, plainText.length, cipherText, 0);
52
ci.doFinal(cipherText, offset);
53
// Decryption
54
byte[] recoveredText = new byte[ci.getOutputSize(cipherText.length)];
55
int len = ci.doFinal(cipherText, 0, cipherText.length, recoveredText);
56
// Comparison
57
if (len != plainText.length ||
58
!TestUtilities.equalsBlock(plainText, cipherText, len) ||
59
!TestUtilities.equalsBlock(plainText, recoveredText, len)) {
60
throw new RuntimeException(
61
"Test failed because plainText not equal to cipherText and revoveredText");
62
}
63
}
64
}
65
66