1 /*
2  * Copyright (c) 1997, 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 /*
25  * @test
26  * @bug 4093855
27  * @summary Make sure algorithm names provided to getInstance() are
28  * treated case-insensitive
29  */
30 
31 import java.security.*;
32 
33 public class CaseInsensitiveAlgNames {
34 
main(String[] args)35     public static void main(String[] args)
36         throws NoSuchAlgorithmException, NoSuchProviderException {
37             // MessageDigest without provider
38             MessageDigest md = MessageDigest.getInstance("SHA");
39             md = MessageDigest.getInstance("sha");
40             md = MessageDigest.getInstance("Sha-1");
41             md = MessageDigest.getInstance("shA1");
42 
43             // MessageDigest with provider
44             md = MessageDigest.getInstance("SHA", "SUN");
45             md = MessageDigest.getInstance("sha", "SUN");
46             md = MessageDigest.getInstance("Sha-1", "SUN");
47             md = MessageDigest.getInstance("shA1", "SUN");
48 
49             // KeyPairGenerator without provider
50             KeyPairGenerator kGen = KeyPairGenerator.getInstance("DSA");
51             kGen = KeyPairGenerator.getInstance("dsa");
52             kGen = KeyPairGenerator.getInstance("dSA");
53             kGen = KeyPairGenerator.getInstance("OId.1.2.840.10040.4.1");
54             kGen = KeyPairGenerator.getInstance("1.2.840.10040.4.1");
55 
56             // KeyPairGenerator with provider
57             kGen = KeyPairGenerator.getInstance("DSA", "SUN");
58             kGen = KeyPairGenerator.getInstance("dsa", "SUN");
59             kGen = KeyPairGenerator.getInstance("dSA", "SUN");
60             kGen = KeyPairGenerator.getInstance("OId.1.2.840.10040.4.1",
61                                                 "SUN");
62             kGen = KeyPairGenerator.getInstance("1.2.840.10040.4.1", "SUN");
63     }
64 }
65