Search in sources :

Example 26 with InvalidAlgorithmParameterException

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

the class CertStore2Test method testGetCRLs.

public void testGetCRLs() {
    CertStore certStore = null;
    try {
        certStore = CertStore.getInstance(CERT_STORE_NAME, new MyCertStoreParameters());
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    }
    assertNotNull(certStore);
    try {
        Collection<? extends CRL> ls = certStore.getCRLs(null);
        assertNull(ls);
    } catch (CertStoreException e) {
        fail("unexpected exception: " + e);
    }
    try {
        Collection<? extends CRL> ls = certStore.getCRLs(new MyCRLSelector());
        assertNotNull(ls);
        assertTrue(ls.isEmpty());
    } catch (CertStoreException e) {
        fail("unexpected exception: " + e);
    }
    try {
        certStore.getCRLs(new MyOtherCRLSelector());
        fail("expected CertStoreException");
    } catch (CertStoreException e) {
    // ok
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) CertStoreException(java.security.cert.CertStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CertStore(java.security.cert.CertStore)

Example 27 with InvalidAlgorithmParameterException

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

the class CertStore2Test method testGetInstanceStringCertStoreParameters.

public void testGetInstanceStringCertStoreParameters() {
    try {
        CertStoreParameters parameters = new MyCertStoreParameters();
        CertStore certStore = CertStore.getInstance(CERT_STORE_NAME, parameters);
        assertNotNull(certStore);
        assertNotNull(certStore.getCertStoreParameters());
        assertNotSame(parameters, certStore.getCertStoreParameters());
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    }
    try {
        CertStore certStore = CertStore.getInstance(CERT_STORE_NAME, null);
        assertNotNull(certStore);
        assertNull(certStore.getCertStoreParameters());
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    }
    try {
        CertStore.getInstance("UnknownCertStore", null);
        fail("expected NoSuchAlgorithmException");
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchAlgorithmException e) {
    // ok
    }
    try {
        CertStore.getInstance(CERT_STORE_NAME, new MyOtherCertStoreParameters());
        fail("expected InvalidAlgorithmParameterException");
    } catch (InvalidAlgorithmParameterException e) {
    // ok
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    }
}
Also used : CertStoreParameters(java.security.cert.CertStoreParameters) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CertStore(java.security.cert.CertStore)

Example 28 with InvalidAlgorithmParameterException

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

the class KeyPairGenerator1Test method testKeyPairGenerator13.

/**
     * Test for methods: <code>initialize(int keysize)</code>
     * <code>initialize(int keysize, SecureRandom random)</code>
     * <code>initialize(AlgorithmParameterSpec param)</code>
     * <code>initialize(AlgorithmParameterSpec param, SecureRandom random)</code>
     * <code>generateKeyPair()</code>
     * <code>genKeyPair()</code>
     * Assertion: initialize(int ...) throws InvalidParameterException when
     * keysize in incorrect Assertion: initialize(AlgorithmParameterSpec
     * ...)throws UnsupportedOperationException Assertion: generateKeyPair() and
     * genKeyPair() return not null KeyPair Additional class MyKeyPairGenerator2
     * is used
     */
public void testKeyPairGenerator13() {
    int[] keys = { -1, -250, 1, 63, -512, -1024 };
    SecureRandom random = new SecureRandom();
    KeyPairGenerator mKPG = new MyKeyPairGenerator2(null);
    assertEquals("Algorithm must be null", mKPG.getAlgorithm(), MyKeyPairGenerator2.getResAlgorithm());
    assertNull("genKeyPair() must return null", mKPG.genKeyPair());
    assertNull("generateKeyPair() mut return null", mKPG.generateKeyPair());
    for (int i = 0; i < keys.length; i++) {
        try {
            mKPG.initialize(keys[i]);
            fail("InvalidParameterException must be thrown (key: " + Integer.toString(keys[i]) + ")");
        } catch (InvalidParameterException e) {
        }
        try {
            mKPG.initialize(keys[i], random);
            fail("InvalidParameterException must be thrown (key: " + Integer.toString(keys[i]) + ")");
        } catch (InvalidParameterException e) {
        }
    }
    try {
        mKPG.initialize(64);
    } catch (InvalidParameterException e) {
        fail("Unexpected InvalidParameterException was thrown");
    }
    try {
        mKPG.initialize(64, null);
    } catch (InvalidParameterException e) {
        fail("Unexpected InvalidParameterException was thrown");
    }
    try {
        mKPG.initialize(null, random);
    } catch (UnsupportedOperationException e) {
    // on j2se1.4 this exception is not thrown
    } catch (InvalidAlgorithmParameterException e) {
        fail("Unexpected InvalidAlgorithmParameterException was thrown");
    }
}
Also used : MyKeyPairGenerator2(org.apache.harmony.security.tests.support.MyKeyPairGenerator2) InvalidParameterException(java.security.InvalidParameterException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SecureRandom(java.security.SecureRandom) KeyPairGenerator(java.security.KeyPairGenerator)

Example 29 with InvalidAlgorithmParameterException

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

the class KeyPairGenerator1Test method testKeyPairGenerator11.

/**
     * Test for methods:
     * <code>initialize(int keysize)</code>
     * <code>initialize(int keysize, SecureRandom random)</code>
     * <code>initialize(AlgorithmParameterSpec param)</code>
     * <code>initialize(AlgorithmParameterSpec param, SecureRandom random)</code>
     * Assertion: throws InvalidParameterException or
     * InvalidAlgorithmParameterException when parameters keysize or param are
     * incorrect
     */
public void testKeyPairGenerator11() throws NoSuchAlgorithmException, NoSuchProviderException {
    if (!DSASupported) {
        fail(NotSupportMsg);
        return;
    }
    int[] keys = { -10000, -1024, -1, 0, 10000 };
    KeyPairGenerator[] kpg = createKPGen();
    assertNotNull("KeyPairGenerator objects were not created", kpg);
    SecureRandom random = new SecureRandom();
    AlgorithmParameterSpec aps = null;
    for (int i = 0; i < kpg.length; i++) {
        for (int j = 0; j < keys.length; j++) {
            try {
                kpg[i].initialize(keys[j]);
                kpg[i].initialize(keys[j], random);
            } catch (InvalidParameterException e) {
            }
        }
        try {
            kpg[i].initialize(aps);
            kpg[i].initialize(aps, random);
        } catch (InvalidAlgorithmParameterException e) {
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SecureRandom(java.security.SecureRandom) KeyPairGenerator(java.security.KeyPairGenerator) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Example 30 with InvalidAlgorithmParameterException

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

the class InvalidAlgorithmParameterExceptionTest method testInvalidAlgorithmParameterException01.

/**
     * Test for <code>InvalidAlgorithmParameterException()</code> constructor
     * Assertion: constructs InvalidAlgorithmParameterException with no detail
     * message
     */
public void testInvalidAlgorithmParameterException01() {
    InvalidAlgorithmParameterException tE = new InvalidAlgorithmParameterException();
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException)

Aggregations

InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)394 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)216 InvalidKeyException (java.security.InvalidKeyException)206 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)130 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)114 BadPaddingException (javax.crypto.BadPaddingException)112 Cipher (javax.crypto.Cipher)101 IvParameterSpec (javax.crypto.spec.IvParameterSpec)100 IOException (java.io.IOException)74 SecretKeySpec (javax.crypto.spec.SecretKeySpec)58 NoSuchProviderException (java.security.NoSuchProviderException)56 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)49 CertificateException (java.security.cert.CertificateException)45 KeyStoreException (java.security.KeyStoreException)43 SecureRandom (java.security.SecureRandom)37 SecretKey (javax.crypto.SecretKey)34 BigInteger (java.math.BigInteger)31 KeyPairGenerator (java.security.KeyPairGenerator)27 UnrecoverableKeyException (java.security.UnrecoverableKeyException)27 X509Certificate (java.security.cert.X509Certificate)27