J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 30 | import java.io.PrintStream; |
| 31 | import java.security.*; |
| 32 | import java.security.spec.*; |
| 33 | import java.util.Random; |
| 34 | |
| 35 | import javax.crypto.*; |
| 36 | import javax.crypto.spec.*; |
| 37 | import java.security.Provider; |
| 38 | import com.sun.crypto.provider.*; |
| 39 | |
| 40 | public 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 | } |