jdk/test/com/sun/crypto/provider/Cipher/JCE/Bugs/4686632/Empty.java
changeset 29267 5a9ac0be6ff7
equal deleted inserted replaced
29266:5705356edc61 29267:5a9ac0be6ff7
       
     1 /*
       
     2  * Copyright (c) 2007, 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 import java.lang.String;
       
    25 import javax.crypto.SecretKey;
       
    26 import javax.crypto.Cipher;
       
    27 import javax.crypto.spec.SecretKeySpec;
       
    28 
       
    29 import static java.lang.System.out;
       
    30 
       
    31 /*
       
    32  * @test
       
    33  * @bug 4686632 8048610
       
    34  * @summary  To verify Cipher.init will throw InvalidKeyException with
       
    35  *  Non-empty message when create SecretKeySpec with invalid DES key
       
    36  * @author Kevin Liu
       
    37  */
       
    38 public class Empty {
       
    39     public static void main(String[] args) throws Exception {
       
    40         try {
       
    41             byte master[] = {
       
    42                     0, 1, 2, 3, 4
       
    43             };
       
    44             SecretKey key = new SecretKeySpec(master, "DES");
       
    45             Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
       
    46             cipher.init(Cipher.ENCRYPT_MODE, key);
       
    47             throw new RuntimeException("InvalidKeyException not thrown");
       
    48         } catch (java.security.InvalidKeyException ike) {
       
    49             ike.printStackTrace();
       
    50             if (ike.getMessage() != null) {
       
    51                 out.println("Status -- Passed");
       
    52             } else {
       
    53                 throw new RuntimeException("Error message is not expected when"
       
    54                         + " InvalidKeyException is thrown");
       
    55             }
       
    56 
       
    57         }
       
    58     }
       
    59 }