Search in sources :

Example 1 with MyKeyPairGeneratorSpi

use of org.apache.harmony.security.tests.support.MyKeyPairGeneratorSpi in project j2objc by google.

the class KeyPairGeneratorSpiTest method testKeyPairGeneratorSpi01.

/**
     * Test for <code>KeyPairGeneratorSpi</code> constructor
     * Assertion: constructs KeyPairGeneratorSpi
     */
public void testKeyPairGeneratorSpi01() throws InvalidAlgorithmParameterException, InvalidParameterException {
    KeyPairGeneratorSpi keyPairGen = new MyKeyPairGeneratorSpi();
    AlgorithmParameterSpec pp = null;
    try {
        keyPairGen.initialize(pp, null);
        fail("UnsupportedOperationException must be thrown");
    } catch (UnsupportedOperationException e) {
    }
    keyPairGen.initialize(pp, new SecureRandom());
    keyPairGen.initialize(1024, new SecureRandom());
    try {
        keyPairGen.initialize(-1024, new SecureRandom());
        fail("IllegalArgumentException must be thrown for incorrect keysize");
    } catch (IllegalArgumentException e) {
    }
    try {
        keyPairGen.initialize(1024, null);
        fail("IllegalArgumentException must be thrown");
    } catch (IllegalArgumentException e) {
        assertEquals("Incorrect exception", e.getMessage(), "Invalid random");
    }
    KeyPair kp = keyPairGen.generateKeyPair();
    assertNull("Not null KeyPair", kp);
}
Also used : KeyPair(java.security.KeyPair) MyKeyPairGeneratorSpi(org.apache.harmony.security.tests.support.MyKeyPairGeneratorSpi) SecureRandom(java.security.SecureRandom) MyKeyPairGeneratorSpi(org.apache.harmony.security.tests.support.MyKeyPairGeneratorSpi) KeyPairGeneratorSpi(java.security.KeyPairGeneratorSpi) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Example 2 with MyKeyPairGeneratorSpi

use of org.apache.harmony.security.tests.support.MyKeyPairGeneratorSpi in project robovm by robovm.

the class KeyPairGeneratorSpiTest method testKeyPairGeneratorSpi01.

/**
     * Test for <code>KeyPairGeneratorSpi</code> constructor
     * Assertion: constructs KeyPairGeneratorSpi
     */
public void testKeyPairGeneratorSpi01() throws InvalidAlgorithmParameterException, InvalidParameterException {
    KeyPairGeneratorSpi keyPairGen = new MyKeyPairGeneratorSpi();
    AlgorithmParameterSpec pp = null;
    try {
        keyPairGen.initialize(pp, null);
        fail("UnsupportedOperationException must be thrown");
    } catch (UnsupportedOperationException e) {
    }
    keyPairGen.initialize(pp, new SecureRandom());
    keyPairGen.initialize(1024, new SecureRandom());
    try {
        keyPairGen.initialize(-1024, new SecureRandom());
        fail("IllegalArgumentException must be thrown for incorrect keysize");
    } catch (IllegalArgumentException e) {
    }
    try {
        keyPairGen.initialize(1024, null);
        fail("IllegalArgumentException must be thrown");
    } catch (IllegalArgumentException e) {
        assertEquals("Incorrect exception", e.getMessage(), "Invalid random");
    }
    KeyPair kp = keyPairGen.generateKeyPair();
    assertNull("Not null KeyPair", kp);
}
Also used : KeyPair(java.security.KeyPair) MyKeyPairGeneratorSpi(org.apache.harmony.security.tests.support.MyKeyPairGeneratorSpi) SecureRandom(java.security.SecureRandom) MyKeyPairGeneratorSpi(org.apache.harmony.security.tests.support.MyKeyPairGeneratorSpi) KeyPairGeneratorSpi(java.security.KeyPairGeneratorSpi) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Aggregations

KeyPair (java.security.KeyPair)2 KeyPairGeneratorSpi (java.security.KeyPairGeneratorSpi)2 SecureRandom (java.security.SecureRandom)2 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)2 MyKeyPairGeneratorSpi (org.apache.harmony.security.tests.support.MyKeyPairGeneratorSpi)2