01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.security.tests.provider.crypto;
19:
20: import java.security.KeyFactory;
21: import java.security.MessageDigest;
22: import java.security.NoSuchAlgorithmException;
23: import java.security.NoSuchProviderException;
24: import java.security.SecureRandom;
25: import java.security.Signature;
26:
27: import junit.framework.Test;
28: import junit.framework.TestCase;
29: import junit.framework.TestSuite;
30:
31: /**
32: * Tests against CryptoProvider.
33: */
34: public class CryptoProviderTest extends TestCase {
35:
36: private static final String providerName = "Crypto"; // name of provider
37: private static final String shaprng = "SHA1PRNG"; // name of algorithm
38: private static final String sha_1 = "SHA-1"; // name of algorithm
39: private static final String sha_1_alias = "SHA1"; // alias name
40: private static final String sha_1_alias2 = "SHA"; // alias name
41:
42: private static final String dsaNames[] = { "SHA1withDSA",
43: "SHAwithDSA", "DSAwithSHA1", "SHA1/DSA", "SHA/DSA",
44: "SHA-1/DSA", "DSA", "DSS", "OID.1.2.840.10040.4.3",
45: "1.2.840.10040.4.3", "1.3.14.3.2.13", "1.3.14.3.2.27" };
46:
47: private static final String keyFactoryNames[] = { "DSA",
48: "1.3.14.3.2.12", "1.2.840.10040.4.1" };
49:
50: /**
51: * Test against CryptoProvider() methods.
52: */
53: public void testCrypto() throws NoSuchAlgorithmException,
54: NoSuchProviderException {
55: SecureRandom sr;
56: MessageDigest md;
57: Signature sign;
58: KeyFactory keyFactory;
59:
60: sr = SecureRandom.getInstance(shaprng, providerName);
61:
62: md = MessageDigest.getInstance(sha_1, providerName);
63: md = MessageDigest.getInstance(sha_1_alias, providerName);
64: md = MessageDigest.getInstance(sha_1_alias2, providerName);
65:
66: for (int i = 0; i < dsaNames.length; i++) {
67: sign = Signature.getInstance(dsaNames[i], providerName);
68: }
69:
70: for (int i = 0; i < keyFactoryNames.length; i++) {
71: keyFactory = KeyFactory.getInstance(keyFactoryNames[i],
72: providerName);
73: }
74: }
75:
76: public static Test suite() {
77: return new TestSuite(CryptoProviderTest.class);
78: }
79:
80: public static void main(String[] args) {
81: junit.textui.TestRunner.run(suite());
82: }
83:
84: }
|