Search in sources :

Example 16 with AlgorithmParameterGenerator

use of java.security.AlgorithmParameterGenerator in project jdk8u_jdk by JetBrains.

the class TestDSAGenParameterSpec method testDSAGenParameterSpec.

private static void testDSAGenParameterSpec(DataTuple dataTuple) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidParameterSpecException, InvalidAlgorithmParameterException {
    System.out.printf("Test case: primePLen=%d, " + "subprimeQLen=%d%n", dataTuple.primePLen, dataTuple.subprimeQLen);
    AlgorithmParameterGenerator apg = AlgorithmParameterGenerator.getInstance(ALGORITHM_NAME, PROVIDER_NAME);
    DSAGenParameterSpec genParamSpec = createGenParameterSpec(dataTuple);
    // genParamSpec will be null if IllegalAE is thrown when expected.
    if (genParamSpec == null) {
        return;
    }
    try {
        apg.init(genParamSpec, null);
        AlgorithmParameters param = apg.generateParameters();
        checkParam(param, genParamSpec);
        System.out.println("Test case passed");
    } catch (InvalidParameterException ipe) {
        // implementation in SUN doesn't
        if (!dataTuple.isSunProviderSupported) {
            System.out.println("Test case passed: expected " + "InvalidParameterException is caught");
        } else {
            throw new RuntimeException("Test case failed.", ipe);
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) DSAGenParameterSpec(java.security.spec.DSAGenParameterSpec) AlgorithmParameterGenerator(java.security.AlgorithmParameterGenerator) AlgorithmParameters(java.security.AlgorithmParameters)

Aggregations

AlgorithmParameterGenerator (java.security.AlgorithmParameterGenerator)16 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 AlgorithmParameters (java.security.AlgorithmParameters)5 SecureRandom (java.security.SecureRandom)4 DHParameterSpec (javax.crypto.spec.DHParameterSpec)3 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 NoSuchProviderException (java.security.NoSuchProviderException)2 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)2 BrokenTest (dalvik.annotation.BrokenTest)1 AlgorithmParameterGeneratorSpi (java.security.AlgorithmParameterGeneratorSpi)1 InvalidKeyException (java.security.InvalidKeyException)1 InvalidParameterException (java.security.InvalidParameterException)1 Key (java.security.Key)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 Provider (java.security.Provider)1 DSAGenParameterSpec (java.security.spec.DSAGenParameterSpec)1 SecretKey (javax.crypto.SecretKey)1 DHGenParameterSpec (javax.crypto.spec.DHGenParameterSpec)1 MyAlgorithmParameterGeneratorSpi (org.apache.harmony.security.tests.support.MyAlgorithmParameterGeneratorSpi)1