blob: f0247677b19e7eea908b821aa1cf017fee7f8211 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2002-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 4512524
27 * @summary Verify that AES cipher can work with mode "CBC", "OFB", "CFB"
28 * @author Valerie Peng
29 */
30import java.io.PrintStream;
31import java.security.*;
32import java.security.spec.*;
33import java.util.Random;
34
35import javax.crypto.*;
36import javax.crypto.spec.*;
37import java.security.Provider;
38import com.sun.crypto.provider.*;
39
40public class Test4512524 {
41
42 private static final String ALGO = "AES";
43 private static final String MODE = "CBC";
44 private static final String PADDING = "NoPadding";
45 private static final int KEYSIZE = 16; // in bytes
46
47 public boolean execute() throws Exception {
48
49 Cipher ci = Cipher.getInstance(ALGO+"/"+MODE+"/"+PADDING, "SunJCE");
50
51 // TEST FIX 4512524
52 KeyGenerator kg = KeyGenerator.getInstance(ALGO, "SunJCE");
53 kg.init(KEYSIZE*8);
54 SecretKey key = kg.generateKey();
55
56 try{
57 AlgorithmParameterSpec aps = null;
58 ci.init(Cipher.ENCRYPT_MODE, key, aps);
59 } catch (NullPointerException ex) {
60 throw new Exception("null parameter is not handled correctly!");
61 }
62
63 // passed all tests...hooray!
64 return true;
65 }
66
67 public static void main (String[] args) throws Exception {
68 Security.addProvider(new com.sun.crypto.provider.SunJCE());
69
70 Test4512524 test = new Test4512524();
71 String testName = test.getClass().getName() + "[" + ALGO +
72 "/" + MODE + "/" + PADDING + "]";
73 if (test.execute()) {
74 System.out.println(testName + ": Passed!");
75 }
76 }
77}