2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package tests.security.interfaces;
17 import dalvik.annotation.BrokenTest;
18 import dalvik.annotation.TestLevel;
19 import dalvik.annotation.TestTargetNew;
20 import dalvik.annotation.TestTargetClass;
22 import junit.framework.TestCase;
24 import java.security.KeyPair;
25 import java.security.KeyPairGenerator;
26 import java.security.SecureRandom;
27 import java.security.interfaces.DSAPrivateKey;
28 import java.security.interfaces.DSAPublicKey;
29 import java.security.spec.DSAParameterSpec;
31 @TestTargetClass(DSAPublicKey.class)
32 public class DSAPublicKeyTest extends TestCase {
35 * @tests java.security.interfaces.DSAPublicKey
37 * test covers following use cases
38 * Case 1: check with predefined p, q, g, x
39 * Case 2: check with random p, q, g, x. It takes some time (up to
43 level = TestLevel.COMPLETE,
48 public void test_getY() throws Exception {
49 KeyPairGenerator keyGen = null;
51 DSAPrivateKey priv = null;
52 DSAPublicKey publ = null;
54 // Case 1: check with predefined p, q, g, x
55 keyGen = KeyPairGenerator.getInstance("DSA");
56 keyGen.initialize(new DSAParameterSpec(Util.P, Util.Q, Util.G),
57 new SecureRandom(new MySecureRandomSpi(), null) {
59 keys = keyGen.generateKeyPair();
60 priv = (DSAPrivateKey) keys.getPrivate();
61 publ = (DSAPublicKey) keys.getPublic();
62 assertNotNull("Invalid Y value", publ.getY());
64 // Case 2: check with random p, q, g, x. It takes some time (up to
66 keyGen = KeyPairGenerator.getInstance("DSA");
67 keys = keyGen.generateKeyPair();
68 priv = (DSAPrivateKey) keys.getPrivate();
69 publ = (DSAPublicKey) keys.getPublic();
70 assertNotNull("Invalid Y value", publ.getY());