Search in sources :

Example 11 with InvalidParameterException

use of java.security.InvalidParameterException 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 12 with InvalidParameterException

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

the class InvalidParameterExceptionTest method testInvalidParameterException01.

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

Example 13 with InvalidParameterException

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

the class InvalidParameterExceptionTest method testInvalidParameterException03.

/**
     * Test for <code>InvalidParameterException(String)</code> constructor
     * Assertion: constructs InvalidParameterException when <code>msg</code>
     * is null
     */
public void testInvalidParameterException03() {
    String msg = null;
    InvalidParameterException tE = new InvalidParameterException(msg);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : InvalidParameterException(java.security.InvalidParameterException)

Example 14 with InvalidParameterException

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

the class CipherSpi method engineInit.

protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
    CipherParameters param;
    if (params == null || params instanceof OAEPParameterSpec) {
        if (key instanceof RSAPublicKey) {
            if (privateKeyOnly && opmode == Cipher.ENCRYPT_MODE) {
                throw new InvalidKeyException("mode 1 requires RSAPrivateKey");
            }
            param = RSAUtil.generatePublicKeyParameter((RSAPublicKey) key);
        } else if (key instanceof RSAPrivateKey) {
            if (publicKeyOnly && opmode == Cipher.ENCRYPT_MODE) {
                throw new InvalidKeyException("mode 2 requires RSAPublicKey");
            }
            param = RSAUtil.generatePrivateKeyParameter((RSAPrivateKey) key);
        } else {
            throw new InvalidKeyException("unknown key type passed to RSA");
        }
        if (params != null) {
            OAEPParameterSpec spec = (OAEPParameterSpec) params;
            paramSpec = params;
            if (!spec.getMGFAlgorithm().equalsIgnoreCase("MGF1") && !spec.getMGFAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1.getId())) {
                throw new InvalidAlgorithmParameterException("unknown mask generation function specified");
            }
            if (!(spec.getMGFParameters() instanceof MGF1ParameterSpec)) {
                throw new InvalidAlgorithmParameterException("unkown MGF parameters");
            }
            Digest digest = DigestFactory.getDigest(spec.getDigestAlgorithm());
            if (digest == null) {
                throw new InvalidAlgorithmParameterException("no match on digest algorithm: " + spec.getDigestAlgorithm());
            }
            MGF1ParameterSpec mgfParams = (MGF1ParameterSpec) spec.getMGFParameters();
            Digest mgfDigest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
            if (mgfDigest == null) {
                throw new InvalidAlgorithmParameterException("no match on MGF digest algorithm: " + mgfParams.getDigestAlgorithm());
            }
            cipher = new OAEPEncoding(new RSABlindedEngine(), digest, mgfDigest, ((PSource.PSpecified) spec.getPSource()).getValue());
        }
    } else {
        throw new IllegalArgumentException("unknown parameter type.");
    }
    if (!(cipher instanceof RSABlindedEngine)) {
        if (random != null) {
            param = new ParametersWithRandom(param, random);
        } else {
            param = new ParametersWithRandom(param, new SecureRandom());
        }
    }
    bOut.reset();
    switch(opmode) {
        case Cipher.ENCRYPT_MODE:
        case Cipher.WRAP_MODE:
            cipher.init(true, param);
            break;
        case Cipher.DECRYPT_MODE:
        case Cipher.UNWRAP_MODE:
            cipher.init(false, param);
            break;
        default:
            throw new InvalidParameterException("unknown opmode " + opmode + " passed to RSA");
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) Digest(org.bouncycastle.crypto.Digest) ParametersWithRandom(org.bouncycastle.crypto.params.ParametersWithRandom) SecureRandom(java.security.SecureRandom) InvalidKeyException(java.security.InvalidKeyException) OAEPParameterSpec(javax.crypto.spec.OAEPParameterSpec) CipherParameters(org.bouncycastle.crypto.CipherParameters) InvalidParameterException(java.security.InvalidParameterException) RSAPublicKey(java.security.interfaces.RSAPublicKey) RSABlindedEngine(org.bouncycastle.crypto.engines.RSABlindedEngine) OAEPEncoding(org.bouncycastle.crypto.encodings.OAEPEncoding) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) MGF1ParameterSpec(java.security.spec.MGF1ParameterSpec)

Example 15 with InvalidParameterException

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

the class SignatureTest method testGetParameter.

@SuppressWarnings("deprecation")
public void testGetParameter() {
    MySignature1 s = new MySignature1("ABC");
    s.getParameter("aaa");
    try {
        MySignature se = new MySignature();
        se.getParameter("test");
    } catch (InvalidParameterException e) {
    // ok
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) MySignature1(org.apache.harmony.security.tests.support.MySignature1)

Aggregations

InvalidParameterException (java.security.InvalidParameterException)280 IOException (java.io.IOException)34 ArrayList (java.util.ArrayList)24 ActionEvent (com.cloud.event.ActionEvent)22 SecureRandom (java.security.SecureRandom)19 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)18 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)16 File (java.io.File)16 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)15 FirewallRule (com.cloud.network.rules.FirewallRule)14 DB (com.cloud.utils.db.DB)14 Map (java.util.Map)14 HashMap (java.util.HashMap)12 MalformedURLException (java.net.MalformedURLException)11 Paint (android.graphics.Paint)9 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)8 CommunicationException (com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException)8 HttpURLConnection (java.net.HttpURLConnection)8 Scanner (java.util.Scanner)8