32766
|
1 |
/*
|
|
2 |
* Copyright (c) 2001, 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 |
* @test
|
|
25 |
* @bug 8048604
|
|
26 |
* @library /lib/testlibrary/
|
|
27 |
* @summary This test verifies the assertion "There should be no transformation
|
|
28 |
* on the plaintext/ciphertext in encryption/decryption mechanism" for
|
|
29 |
* feature "NullCipher".
|
|
30 |
*/
|
|
31 |
import javax.crypto.BadPaddingException;
|
|
32 |
import javax.crypto.Cipher;
|
|
33 |
import javax.crypto.IllegalBlockSizeException;
|
|
34 |
import javax.crypto.NullCipher;
|
|
35 |
import javax.crypto.ShortBufferException;
|
|
36 |
import jdk.testlibrary.RandomFactory;
|
|
37 |
|
|
38 |
public class CipherNCFuncTest {
|
|
39 |
public static void main(String[] args) throws ShortBufferException,
|
|
40 |
IllegalBlockSizeException, BadPaddingException {
|
|
41 |
byte[] plainText = new byte[801];
|
|
42 |
// Initialization
|
|
43 |
RandomFactory.getRandom().nextBytes(plainText);
|
|
44 |
Cipher ci = new NullCipher();
|
|
45 |
// Encryption
|
|
46 |
byte[] cipherText = new byte[ci.getOutputSize(plainText.length)];
|
|
47 |
int offset = ci.update(plainText, 0, plainText.length, cipherText, 0);
|
|
48 |
ci.doFinal(cipherText, offset);
|
|
49 |
// Decryption
|
|
50 |
byte[] recoveredText = new byte[ci.getOutputSize(cipherText.length)];
|
|
51 |
int len = ci.doFinal(cipherText, 0, cipherText.length, recoveredText);
|
|
52 |
// Comparison
|
|
53 |
if (len != plainText.length ||
|
|
54 |
!TestUtilities.equalsBlock(plainText, cipherText, len) ||
|
|
55 |
!TestUtilities.equalsBlock(plainText, recoveredText, len)) {
|
|
56 |
throw new RuntimeException(
|
|
57 |
"Test failed because plainText not equal to cipherText and revoveredText");
|
|
58 |
}
|
|
59 |
}
|
|
60 |
}
|