Search in sources :

Example 21 with Provider

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

the class ExemptionMechanismTest method test_getName.

public void test_getName() throws Exception {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
    ExemptionMechanism em = new ExemptionMechanism(new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };
    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
    assertEquals(defaultAlg, em.getName());
}
Also used : SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) MyExemptionMechanismSpi(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi) ExemptionMechanism(javax.crypto.ExemptionMechanism) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Key(java.security.Key) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Provider(java.security.Provider)

Example 22 with Provider

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

the class KeyAgreementTest method testGetInstanceStringProvider02.

/**
     * Test for <code> getInstance(String algorithm, Provider provider)</code>
     * method Assertions: throws IllegalArgumentException when provider is null
     */
public void testGetInstanceStringProvider02() throws NoSuchAlgorithmException, IllegalArgumentException {
    if (!DEFSupported) {
        fail(NotSupportMsg);
        return;
    }
    Provider provider = null;
    for (int i = 0; i < invalidValues.length; i++) {
        try {
            KeyAgreement.getInstance(invalidValues[i], provider);
            fail("IllegalArgumentException must be thrown");
        } catch (IllegalArgumentException e) {
        }
    }
}
Also used : Provider(java.security.Provider)

Example 23 with Provider

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

the class myMac method testMac06.

/**
     * Test for <code>getInstance(String algorithm, Provider provider)</code> method
     * Assertion: throws IllegalArgumentException when provider is null
     */
public void testMac06() throws NoSuchAlgorithmException, NoSuchProviderException {
    if (!DEFSupported) {
        fail(NotSupportedMsg);
        return;
    }
    Provider provider = null;
    for (int i = 0; i < validValues.length; i++) {
        try {
            Mac.getInstance(validValues[i], provider);
            fail("IllegalArgumentException must be thrown when provider is null");
        } catch (IllegalArgumentException e) {
        }
    }
}
Also used : Provider(java.security.Provider)

Example 24 with Provider

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

the class Cipher method getCipher.

/**
     * Find appropriate Cipher according the specification rules
     *
     * @param transformation
     * @param provider
     * @return
     * @throws NoSuchAlgorithmException
     * @throws NoSuchPaddingException
     */
private static synchronized Cipher getCipher(String transformation, Provider provider) throws NoSuchAlgorithmException, NoSuchPaddingException {
    if (transformation == null || transformation.isEmpty()) {
        throw invalidTransformation(transformation);
    }
    String[] transf = checkTransformation(transformation);
    boolean needSetPadding = false;
    boolean needSetMode = false;
    Object engineSpi = null;
    Provider engineProvider = provider;
    if (transf[1] == null && transf[2] == null) {
        // "algorithm"
        if (provider == null) {
            Engine.SpiAndProvider sap = ENGINE.getInstance(transf[0], null);
            engineSpi = sap.spi;
            engineProvider = sap.provider;
        } else {
            engineSpi = ENGINE.getInstance(transf[0], provider, null);
        }
    } else {
        String[] searchOrder = { // "algorithm/mode/padding"
        transf[0] + "/" + transf[1] + "/" + transf[2], // "algorithm/mode"
        transf[0] + "/" + transf[1], // "algorithm//padding"
        transf[0] + "//" + transf[2], // "algorithm"
        transf[0] };
        int i;
        for (i = 0; i < searchOrder.length; i++) {
            try {
                if (provider == null) {
                    Engine.SpiAndProvider sap = ENGINE.getInstance(searchOrder[i], null);
                    engineSpi = sap.spi;
                    engineProvider = sap.provider;
                } else {
                    engineSpi = ENGINE.getInstance(searchOrder[i], provider, null);
                }
                break;
            } catch (NoSuchAlgorithmException e) {
                if (i == searchOrder.length - 1) {
                    throw new NoSuchAlgorithmException(transformation, e);
                }
            }
        }
        switch(i) {
            case // "algorithm/mode"
            1:
                needSetPadding = true;
                break;
            case // "algorithm//padding"
            2:
                needSetMode = true;
                break;
            case // "algorithm"
            3:
                needSetPadding = true;
                needSetMode = true;
        }
    }
    if (engineSpi == null || engineProvider == null) {
        throw new NoSuchAlgorithmException(transformation);
    }
    if (!(engineSpi instanceof CipherSpi)) {
        throw new NoSuchAlgorithmException(engineSpi.getClass().getName());
    }
    CipherSpi cspi = (CipherSpi) engineSpi;
    Cipher c = new Cipher(cspi, engineProvider, transformation);
    if (needSetMode) {
        c.spiImpl.engineSetMode(transf[1]);
    }
    if (needSetPadding) {
        c.spiImpl.engineSetPadding(transf[2]);
    }
    return c;
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NullCipherSpi(org.apache.harmony.crypto.internal.NullCipherSpi) Engine(org.apache.harmony.security.fortress.Engine) Provider(java.security.Provider)

Example 25 with Provider

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

the class SignatureTest method getTestSignature.

private Signature getTestSignature() throws NoSuchAlgorithmException {
    Provider provider = new MyProvider("TestProvider", 1.0, "Test Provider", "Signature.ABC", MySignature.class.getName());
    Security.insertProviderAt(provider, 1);
    try {
        return Signature.getInstance("ABC");
    } finally {
        Security.removeProvider("TestProvider");
    }
}
Also used : 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