791N/A/*
791N/A * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved.
791N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
791N/A *
791N/A * This code is free software; you can redistribute it and/or modify it
791N/A * under the terms of the GNU General Public License version 2 only, as
791N/A * published by the Free Software Foundation.
791N/A *
791N/A * This code is distributed in the hope that it will be useful, but WITHOUT
791N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
791N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
791N/A * version 2 for more details (a copy is included in the LICENSE file that
791N/A * accompanied this code).
791N/A *
791N/A * You should have received a copy of the GNU General Public License version
791N/A * 2 along with this work; if not, write to the Free Software Foundation,
791N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
791N/A *
791N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
791N/A * or visit www.oracle.com if you need additional information or have any
791N/A * questions.
791N/A */
791N/A
791N/A/*
791N/A * @test
791N/A * @bug 6209660
791N/A * @summary Ensure that InvalidAlgorithmParameterException is
791N/A * thrown as javadoc specified when parameters of the wrong
791N/A * type are used.
791N/A * @author Valerie Peng
791N/A */
791N/Aimport java.security.*;
791N/Aimport java.security.spec.*;
791N/Aimport javax.crypto.*;
791N/Aimport javax.crypto.spec.*;
791N/A
791N/Apublic class PBEInvalidParamsTest {
791N/A
791N/A private static final char[] PASSWORD = { 'p', 'a', 's', 's' };
791N/A private static final String[] PBE_ALGOS = {
791N/A "PBEWithMD5AndDES", "PBEWithSHA1AndDESede", "PBEWithSHA1AndRC2_40"
791N/A // skip "PBEWithMD5AndTripleDES" since it requires Unlimited
791N/A // version of JCE jurisdiction policy files.
791N/A };
791N/A
791N/A private static final IvParameterSpec INVALID_PARAMS =
791N/A new IvParameterSpec(new byte[8]);
791N/A
791N/A public static void main(String[] args) throws Exception {
791N/A PBEKeySpec ks = new PBEKeySpec(PASSWORD);
791N/A for (int i = 0; i < PBE_ALGOS.length; i++) {
791N/A String algo = PBE_ALGOS[i];
791N/A System.out.println("=>testing " + algo);
791N/A SecretKeyFactory skf = SecretKeyFactory.getInstance(algo);
791N/A SecretKey key = skf.generateSecret(ks);
791N/A Cipher c = Cipher.getInstance(algo, "SunJCE");
791N/A try {
791N/A c.init(Cipher.ENCRYPT_MODE, key, INVALID_PARAMS);
791N/A throw new Exception("Test Failed: expected IAPE is " +
791N/A "not thrown for " + algo);
791N/A } catch (InvalidAlgorithmParameterException iape) {
791N/A continue;
791N/A }
791N/A }
791N/A System.out.println("Test Passed");
791N/A }
791N/A}
791N/A