Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/crypto/provider/CICO/PBEFunc/CipherNCFuncTest.java
38889 views
/*1* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 804860425* @library ../ /lib/testlibrary26* @summary This test verifies the assertion "There should be no transformation27* on the plaintext/ciphertext in encryption/decryption mechanism" for28* feature "NullCipher".29*/30import javax.crypto.BadPaddingException;31import javax.crypto.Cipher;32import javax.crypto.IllegalBlockSizeException;33import javax.crypto.NullCipher;34import javax.crypto.ShortBufferException;35import jdk.testlibrary.RandomFactory;3637public class CipherNCFuncTest {38public static void main(String[] args) throws ShortBufferException,39IllegalBlockSizeException, BadPaddingException {40byte[] plainText = new byte[801];41// Initialization42RandomFactory.getRandom().nextBytes(plainText);43Cipher ci = new NullCipher();44// Encryption45byte[] cipherText = new byte[ci.getOutputSize(plainText.length)];46int offset = ci.update(plainText, 0, plainText.length, cipherText, 0);47ci.doFinal(cipherText, offset);48// Decryption49byte[] recoveredText = new byte[ci.getOutputSize(cipherText.length)];50int len = ci.doFinal(cipherText, 0, cipherText.length, recoveredText);51// Comparison52if (len != plainText.length ||53!TestUtilities.equalsBlock(plainText, cipherText, len) ||54!TestUtilities.equalsBlock(plainText, recoveredText, len)) {55throw new RuntimeException(56"Test failed because plainText not equal to cipherText and revoveredText");57}58}59}606162