Search in sources :

Example 61 with NoSuchProviderException

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

the class invalidParams method testCertPathValidator13.

/**
     * Test for <code>getAlgorithm()</code> method
     */
public void testCertPathValidator13() throws NoSuchAlgorithmException {
    if (!PKIXSupport) {
        fail(NotSupportMsg);
        return;
    }
    CertPathValidator certPV;
    for (int i = 0; i < validValues.length; i++) {
        certPV = CertPathValidator.getInstance(validValues[i]);
        assertEquals("Incorrect algorithm", certPV.getAlgorithm(), validValues[i]);
        try {
            certPV = CertPathValidator.getInstance(validValues[i], defaultProviderName);
            assertEquals("Incorrect algorithm", certPV.getAlgorithm(), validValues[i]);
        } catch (NoSuchProviderException e) {
            fail("Unexpected NoSuchAlgorithmException " + e.getMessage());
        }
        certPV = CertPathValidator.getInstance(validValues[i], defaultProvider);
        assertEquals("Incorrect algorithm", certPV.getAlgorithm(), validValues[i]);
    }
}
Also used : CertPathValidator(java.security.cert.CertPathValidator) NoSuchProviderException(java.security.NoSuchProviderException)

Example 62 with NoSuchProviderException

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

the class CipherTest method test_getInstanceLjava_lang_StringLjava_lang_String.

/**
     * javax.crypto.Cipher#getInstance(java.lang.String,
     *        java.lang.String)
     */
public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception {
    Provider[] providers = Security.getProviders("Cipher.DES");
    assertNotNull("No installed providers support Cipher.DES", providers);
    for (int i = 0; i < providers.length; i++) {
        Cipher cipher = Cipher.getInstance("DES", providers[i].getName());
        assertNotNull("Cipher.getInstance() returned a null value", cipher);
        try {
            cipher = Cipher.getInstance("DoBeDoBeDo", providers[i]);
            fail();
        } catch (NoSuchAlgorithmException expected) {
        }
    }
    try {
        Cipher.getInstance("DES", (String) null);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    try {
        Cipher.getInstance("DES", "IHaveNotBeenConfigured");
        fail();
    } catch (NoSuchProviderException expected) {
    }
}
Also used : Cipher(javax.crypto.Cipher) MyCipher(org.apache.harmony.crypto.tests.support.MyCipher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) Provider(java.security.Provider)

Example 63 with NoSuchProviderException

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

the class EncryptedPrivateKeyInfoTest method testGetKeySpecKeyString01.

public final void testGetKeySpecKeyString01() throws Exception {
    boolean performed = false;
    for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
        try {
            EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfoData.algName0[i][0], EncryptedPrivateKeyInfoData.encryptedData);
            try {
                // check that method under test throws NPE
                epki.getKeySpec((Key) null, "SomeProviderName");
                fail(getName() + "NullPointerException has not been thrown");
            } catch (NullPointerException ok) {
            }
            try {
                epki.getKeySpec(new Key() {

                    public String getAlgorithm() {
                        return "alg";
                    }

                    public String getFormat() {
                        return "fmt";
                    }

                    public byte[] getEncoded() {
                        return new byte[] {};
                    }
                }, "StrangeProviderName");
                fail(getName() + "NoSuchProviderException has not been thrown");
            } catch (NoSuchProviderException ok) {
            //expected
            }
            try {
                // check that method under test throws NPE
                epki.getKeySpec(new Key() {

                    public String getAlgorithm() {
                        return "alg";
                    }

                    public String getFormat() {
                        return "fmt";
                    }

                    public byte[] getEncoded() {
                        return new byte[] {};
                    }
                }, (String) null);
                fail(getName() + "NullPointerException has not been thrown");
            } catch (NullPointerException ok) {
            }
            performed = true;
        } catch (NoSuchAlgorithmException allowedFailure) {
        }
    }
    assertTrue("Test not performed", performed);
}
Also used : EncryptedPrivateKeyInfo(javax.crypto.EncryptedPrivateKeyInfo) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) Key(java.security.Key)

Example 64 with NoSuchProviderException

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

the class AlgorithmParametersTest method test_getInstanceLjava_lang_StringLjava_lang_String.

/**
     * java.security.AlgorithmParameters#getInstance(String, String)
     */
public void test_getInstanceLjava_lang_StringLjava_lang_String() {
    String[] alg = { "", "qwertyu", "!@#$%^&*()" };
    String[] prv = { "", null };
    String[] prv1 = { "1234567890", "qwertyu", "!@#$%^&*()" };
    try {
        AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", "MyProvider");
        checkUnititialized(ap);
        ap.init(new byte[6]);
        checkAP(ap, p);
    } catch (Exception e) {
        fail("Unexpected exception");
    }
    for (int i = 0; i < alg.length; i++) {
        try {
            AlgorithmParameters ap = AlgorithmParameters.getInstance(alg[i], "MyProvider");
            fail("NoSuchAlgorithmException was not thrown for parameter " + alg[i]);
        } catch (NoSuchAlgorithmException nsae) {
        //expected
        } catch (Exception e) {
            fail("Incorrect exception " + e + " was thrown for " + alg[i]);
        }
    }
    for (int i = 0; i < prv.length; i++) {
        try {
            AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", prv[i]);
            fail("IllegalArgumentException was not thrown for parameter " + prv[i]);
        } catch (IllegalArgumentException iae) {
        //expected
        } catch (Exception e) {
            fail("Incorrect exception " + e + " was thrown for " + prv[i]);
        }
    }
    for (int i = 0; i < prv1.length; i++) {
        try {
            AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", prv1[i]);
            fail("NoSuchProviderException was not thrown for parameter " + prv1[i]);
        } catch (NoSuchProviderException nspe) {
        //expected
        } catch (Exception e) {
            fail("Incorrect exception " + e + " was thrown for " + prv1[i]);
        }
    }
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) NoSuchProviderException(java.security.NoSuchProviderException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 65 with NoSuchProviderException

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

the class NoSuchProviderExceptionTest method testNoSuchProviderException01.

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

Aggregations

NoSuchProviderException (java.security.NoSuchProviderException)93 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)67 InvalidKeyException (java.security.InvalidKeyException)30 IOException (java.io.IOException)28 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)18 CertificateException (java.security.cert.CertificateException)18 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)14 Cipher (javax.crypto.Cipher)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 BadPaddingException (javax.crypto.BadPaddingException)12 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)12 KeyStoreException (java.security.KeyStoreException)11 SignatureException (java.security.SignatureException)10 X509Certificate (java.security.cert.X509Certificate)10 SecretKey (javax.crypto.SecretKey)10 CertificateFactory (java.security.cert.CertificateFactory)9 CertificateEncodingException (java.security.cert.CertificateEncodingException)8 IvParameterSpec (javax.crypto.spec.IvParameterSpec)8 KeyStore (java.security.KeyStore)7 Provider (java.security.Provider)7