Search in sources :

Example 1 with AlgorithmParameterGenerator

use of java.security.AlgorithmParameterGenerator in project robovm by robovm.

the class myAlgPG method testAlgorithmParameterGenerator10.

/**
     * Test for <code>generateParameters()</code> method
     * Assertion: returns AlgorithmParameters object
     */
public void testAlgorithmParameterGenerator10() throws NoSuchAlgorithmException {
    if (!DSASupported) {
        fail(validAlgName + " algorithm is not supported");
        return;
    }
    AlgorithmParameterGenerator apg = AlgorithmParameterGenerator.getInstance(validAlgName);
    apg.init(512);
    AlgorithmParameters ap = apg.generateParameters();
    assertEquals("Incorrect algorithm", ap.getAlgorithm().toUpperCase(), apg.getAlgorithm().toUpperCase());
}
Also used : AlgorithmParameterGenerator(java.security.AlgorithmParameterGenerator) AlgorithmParameters(java.security.AlgorithmParameters)

Example 2 with AlgorithmParameterGenerator

use of java.security.AlgorithmParameterGenerator in project robovm by robovm.

the class myAlgPG method testAlgorithmParameterGenerator09.

/**
     * Test for <code>getInstance(String algorithm, Provider provider)</code>
     * method
     * Assertion: returns AlgorithmParameterGenerator object
     */
public void testAlgorithmParameterGenerator09() throws NoSuchAlgorithmException {
    if (!DSASupported) {
        fail(validAlgName + " algorithm is not supported");
        return;
    }
    AlgorithmParameterGenerator apg;
    for (int i = 0; i < algs.length; i++) {
        apg = AlgorithmParameterGenerator.getInstance(algs[i], validProvider);
        assertEquals("Incorrect algorithm", apg.getAlgorithm(), algs[i]);
        assertEquals("Incorrect provider", apg.getProvider(), validProvider);
    }
}
Also used : AlgorithmParameterGenerator(java.security.AlgorithmParameterGenerator)

Example 3 with AlgorithmParameterGenerator

use of java.security.AlgorithmParameterGenerator in project robovm by robovm.

the class myAlgPG method testAlgorithmParameterGenerator06.

/**
     * Test for <code>getInstance(String algorithm, String provider)</code>
     * method
     * Assertion: return AlgorithmParameterGenerator
     */
public void testAlgorithmParameterGenerator06() throws NoSuchAlgorithmException, NoSuchProviderException {
    if (!DSASupported) {
        fail(validAlgName + " algorithm is not supported");
        return;
    }
    AlgorithmParameterGenerator apg;
    for (int i = 0; i < algs.length; i++) {
        apg = AlgorithmParameterGenerator.getInstance(algs[i], validProviderName);
        assertEquals("Incorrect algorithm", algs[i], apg.getAlgorithm());
        assertEquals("Incorrect provider", apg.getProvider().getName(), validProviderName);
    }
}
Also used : AlgorithmParameterGenerator(java.security.AlgorithmParameterGenerator)

Example 4 with AlgorithmParameterGenerator

use of java.security.AlgorithmParameterGenerator in project robovm by robovm.

the class myAlgPG method testAlgorithmParameterGenerator12.

/**
     * Test for <code>init(AlgorithmParameterSpec param)</code> and
     * <code>init(AlgorithmParameterSpec param, SecureRandom random<code>
     * methods
     * Assertion: throws InvalidAlgorithmParameterException when param is null
     */
public void testAlgorithmParameterGenerator12() {
    if (!DSASupported) {
        fail(validAlgName + " algorithm is not supported");
        return;
    }
    SecureRandom random = new SecureRandom();
    AlgorithmParameterSpec aps = null;
    AlgorithmParameterGenerator[] apgs = createAPGen();
    assertNotNull("AlgorithmParameterGenerator objects were not created", apgs);
    for (int i = 0; i < apgs.length; i++) {
        try {
            apgs[i].init(aps);
            fail("InvalidAlgorithmParameterException expected for null argument.");
        } catch (InvalidAlgorithmParameterException e) {
        //expected
        }
        try {
            apgs[i].init(aps, random);
            fail("InvalidAlgorithmParameterException expected for null argument.");
        } catch (InvalidAlgorithmParameterException e) {
        //expected
        }
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SecureRandom(java.security.SecureRandom) AlgorithmParameterGenerator(java.security.AlgorithmParameterGenerator) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Example 5 with AlgorithmParameterGenerator

use of java.security.AlgorithmParameterGenerator in project robovm by robovm.

the class myAlgPG method testConstructor.

/**
     * Test for <code>AlgorithmParameterGenerator</code> constructor
     * Assertion: returns AlgorithmParameterGenerator object
     */
public void testConstructor() throws NoSuchAlgorithmException {
    if (!DSASupported) {
        fail(validAlgName + " algorithm is not supported");
        return;
    }
    AlgorithmParameterGeneratorSpi spi = new MyAlgorithmParameterGeneratorSpi();
    AlgorithmParameterGenerator apg = new myAlgPG(spi, validProvider, validAlgName);
    assertEquals("Incorrect algorithm", apg.getAlgorithm(), validAlgName);
    assertEquals("Incorrect provider", apg.getProvider(), validProvider);
    try {
        apg.init(-10, null);
        fail("IllegalArgumentException must be thrown");
    } catch (IllegalArgumentException e) {
    }
    apg = new myAlgPG(null, null, null);
    assertNull("Incorrect algorithm", apg.getAlgorithm());
    assertNull("Incorrect provider", apg.getProvider());
    try {
        apg.init(-10, null);
        fail("NullPointerException must be thrown");
    } catch (NullPointerException e) {
    }
}
Also used : MyAlgorithmParameterGeneratorSpi(org.apache.harmony.security.tests.support.MyAlgorithmParameterGeneratorSpi) AlgorithmParameterGenerator(java.security.AlgorithmParameterGenerator) AlgorithmParameterGeneratorSpi(java.security.AlgorithmParameterGeneratorSpi) MyAlgorithmParameterGeneratorSpi(org.apache.harmony.security.tests.support.MyAlgorithmParameterGeneratorSpi)

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