blob: fce42249fe8a5ae28e5e089380c768c44f5bd5a6 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005-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 6341599
27 * @summary JCE Reference Guide has recommendations, not requirements,
28 * for algorithm names
29 * @author Brad R. Wetmore
30 */
31import javax.crypto.*;
32import java.security.spec.*;
33import javax.crypto.spec.*;
34
35public class PBEKeysAlgorithmNames {
36
37 static String [] algs = {
38 "PBEWithMD5AndDES",
39 "PBEWithSHA1AndDESede",
40 "PBEWithSHA1AndRC2_40",
41 "PBKDF2WithHmacSHA1",
42 "PBEWithMD5AndTripleDES"
43 };
44
45 public static void main(String[] argv) throws Exception {
46
47 byte [] b = new byte[64];
48
49 PBEKeySpec pbeks = new PBEKeySpec("password".toCharArray(), b, 20, 60);
50
51 for (String s : algs) {
52 System.out.println("Testing " + s);
53 SecretKeyFactory skf = SecretKeyFactory.getInstance(s, "SunJCE");
54
55 System.out.println(" Checking skf.getAlgorithm()");
56 if (!skf.getAlgorithm().equalsIgnoreCase(s)) {
57 throw new Exception("getAlgorithm() \n\"" +
58 skf.getAlgorithm() + "\" != \"" + s + "\"");
59 }
60
61 System.out.println(" Checking skf.generateSecret()");
62 SecretKey sk = skf.generateSecret(pbeks);
63 if (!sk.getAlgorithm().equalsIgnoreCase(s)) {
64 throw new Exception("getAlgorithm() \n\"" +
65 sk.getAlgorithm() + "\" != \"" + s + "\"");
66 }
67
68 System.out.println(" Checking skf.translateKey()");
69 SecretKey sk1 = skf.translateKey(sk);
70 if (!sk1.getAlgorithm().equalsIgnoreCase(s)) {
71 throw new Exception(" getAlgorithm() \n\"" +
72 sk.getAlgorithm() + "\" != \"" + s + "\"");
73 }
74
75 System.out.println(" Checking skf.getKeySpec()");
76 KeySpec ks = skf.getKeySpec(sk, PBEKeySpec.class);
77
78 System.out.println(" passed.\n");
79 }
80
81 System.out.println("Test Passed");
82 }
83}