Search in sources :

Example 6 with Provider

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

the class Services method removeProvider.

/**
     * Removes the provider at the specified 1-based position.
     */
public static synchronized void removeProvider(int providerNumber) {
    Provider p = providers.remove(providerNumber - 1);
    providersNames.remove(p.getName());
    setNeedRefresh();
}
Also used : Provider(java.security.Provider)

Example 7 with Provider

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

the class AlgorithmParameterGenerator2Test method testGetInstance03.

/**
     * Test for <code>getInstance(String algorithm, Provider provider)</code>
     * method
     * Assertions:
     * throws NullPointerException must be thrown is null
     * throws NoSuchAlgorithmException must be thrown if algorithm is not available
     * throws IllegalArgumentException when provider is null;
     * returns AlgorithmParameterGenerator object
     */
public void testGetInstance03() throws NoSuchAlgorithmException, IllegalArgumentException, InvalidAlgorithmParameterException {
    try {
        AlgorithmParameterGenerator.getInstance(null, mProv);
        fail("NullPointerException or NoSuchAlgorithmException should be thrown");
    } catch (NullPointerException e) {
    } catch (NoSuchAlgorithmException e) {
    }
    for (int i = 0; i < invalidValues.length; i++) {
        try {
            AlgorithmParameterGenerator.getInstance(invalidValues[i], mProv);
            fail("NoSuchAlgorithmException must be thrown (algorithm: ".concat(invalidValues[i]).concat(")"));
        } catch (NoSuchAlgorithmException e) {
        }
    }
    Provider prov = null;
    for (int i = 0; i < validValues.length; i++) {
        try {
            AlgorithmParameterGenerator.getInstance(validValues[i], prov);
            fail("IllegalArgumentException must be thrown when provider is null (algorithm: ".concat(invalidValues[i]).concat(")"));
        } catch (IllegalArgumentException e) {
        }
    }
    AlgorithmParameterGenerator apG;
    for (int i = 0; i < validValues.length; i++) {
        apG = AlgorithmParameterGenerator.getInstance(validValues[i], mProv);
        assertEquals("Incorrect algorithm", apG.getAlgorithm(), validValues[i]);
        assertEquals("Incorrect provider", apG.getProvider(), mProv);
        checkResult(apG);
    }
}
Also used : AlgorithmParameterGenerator(java.security.AlgorithmParameterGenerator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Provider(java.security.Provider)

Example 8 with Provider

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

the class CertificateTest method testVerifyMD5.

public void testVerifyMD5() throws Exception {
    Provider[] providers = Security.getProviders("CertificateFactory.X509");
    for (Provider provider : providers) {
        CertificateFactory certificateFactory = CertificateFactory.getInstance("X509", provider);
        Certificate certificate = certificateFactory.generateCertificate(new ByteArrayInputStream(selfSignedCertMD5.getBytes()));
        certificate.verify(certificate.getPublicKey());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateFactory(java.security.cert.CertificateFactory) Provider(java.security.Provider) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 9 with Provider

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

the class MacTest method test_getInstance_OpenSSL_ENGINE.

public void test_getInstance_OpenSSL_ENGINE() throws Exception {
    final String secret = "-HMAC-test1";
    final byte[] testString = "testing123".getBytes();
    Provider p = Security.getProvider(OpenSSLProvider.PROVIDER_NAME);
    NativeCryptoTest.loadTestEngine();
    OpenSSLEngine engine = OpenSSLEngine.getInstance(NativeCryptoTest.TEST_ENGINE_ID);
    /*
         * The "-HMAC-" prefix is a special prefix recognized by
         * test_openssl_engine.cpp
         */
    SecretKey key1 = engine.getSecretKeyById(secret, "HmacSHA256");
    SecretKey key1dupe = engine.getSecretKeyById(secret, "HmacSHA256");
    /* Non-ENGINE-based SecretKey */
    SecretKey key2 = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
    /* The one that is ENGINE-based can't be equal to a non-ENGINE one. */
    assertFalse(key1.equals(key2));
    assertEquals(key1, key1dupe);
    assertNull(key1.getFormat());
    assertNull(key1.getEncoded());
    assertEquals("RAW", key2.getFormat());
    assertEquals(Arrays.toString(secret.getBytes()), Arrays.toString(key2.getEncoded()));
    Mac mac1 = Mac.getInstance("HmacSHA256", p);
    mac1.init(key1);
    mac1.update(testString);
    byte[] output1 = mac1.doFinal();
    assertEquals(mac1.getMacLength(), output1.length);
    Mac mac2 = Mac.getInstance("HmacSHA256", p);
    mac2.init(key2);
    mac2.update(testString);
    byte[] output2 = mac2.doFinal();
    assertEquals(Arrays.toString(output2), Arrays.toString(output1));
}
Also used : SecretKey(javax.crypto.SecretKey) SecretKeySpec(javax.crypto.spec.SecretKeySpec) Mac(javax.crypto.Mac) Provider(java.security.Provider)

Example 10 with Provider

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

the class KeyStoreTest method test_KeyStore_getInstance.

public void test_KeyStore_getInstance() throws Exception {
    String type = KeyStore.getDefaultType();
    try {
        KeyStore.getInstance(null);
        fail(type);
    } catch (NullPointerException expected) {
    }
    assertNotNull(KeyStore.getInstance(type));
    String providerName = StandardNames.SECURITY_PROVIDER_NAME;
    try {
        KeyStore.getInstance(null, (String) null);
        fail(type);
    } catch (IllegalArgumentException expected) {
    }
    try {
        KeyStore.getInstance(null, providerName);
        fail(type);
    } catch (Exception e) {
        if (e.getClass() != NullPointerException.class && e.getClass() != KeyStoreException.class) {
            throw e;
        }
    }
    try {
        KeyStore.getInstance(type, (String) null);
        fail(type);
    } catch (IllegalArgumentException expected) {
    }
    assertNotNull(KeyStore.getInstance(type, providerName));
    Provider provider = Security.getProvider(providerName);
    try {
        KeyStore.getInstance(null, (Provider) null);
        fail(type);
    } catch (IllegalArgumentException expected) {
    }
    try {
        KeyStore.getInstance(null, provider);
        fail(type);
    } catch (NullPointerException expected) {
    }
    try {
        KeyStore.getInstance(type, (Provider) null);
        fail(type);
    } catch (IllegalArgumentException expected) {
    }
    assertNotNull(KeyStore.getInstance(type, provider));
}
Also used : KeyStoreException(java.security.KeyStoreException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Provider(java.security.Provider)

Aggregations

Provider (java.security.Provider)229 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)49 ArrayList (java.util.ArrayList)25 MessageDigest (java.security.MessageDigest)21 KeyStore (java.security.KeyStore)19 List (java.util.List)18 Service (java.security.Provider.Service)15 ExemptionMechanism (javax.crypto.ExemptionMechanism)14 SpiEngUtils (org.apache.harmony.security.tests.support.SpiEngUtils)14 InvalidKeyException (java.security.InvalidKeyException)13 IOException (java.io.IOException)12 Key (java.security.Key)12 NoSuchProviderException (java.security.NoSuchProviderException)12 SecureRandom (java.security.SecureRandom)12 SecretKey (javax.crypto.SecretKey)12 KeyStoreException (java.security.KeyStoreException)11 Cipher (javax.crypto.Cipher)11 KeyGenerator (javax.crypto.KeyGenerator)11 MyExemptionMechanismSpi.tmpKey (org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey)11 CertificateException (java.security.cert.CertificateException)10