Search in sources :

Example 11 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project robovm by robovm.

the class AlgorithmParametersTest method testAlgorithmParameters.

public void testAlgorithmParameters() {
    AlgorithmParameters algorithmParameters = null;
    try {
        algorithmParameters = AlgorithmParameters.getInstance(algorithmName);
    } catch (NoSuchAlgorithmException e) {
        fail(e.getMessage());
    }
    try {
        algorithmParameters.init(parameterData);
    } catch (InvalidParameterSpecException e) {
        fail(e.getMessage());
    }
    helper.test(algorithmParameters);
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 12 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project platform_frameworks_base by android.

the class AndroidKeyStoreUnauthenticatedAESCipherSpi method engineGetParameters.

@Nullable
@Override
protected final AlgorithmParameters engineGetParameters() {
    if (!mIvRequired) {
        return null;
    }
    if ((mIv != null) && (mIv.length > 0)) {
        try {
            AlgorithmParameters params = AlgorithmParameters.getInstance("AES");
            params.init(new IvParameterSpec(mIv));
            return params;
        } catch (NoSuchAlgorithmException e) {
            throw new ProviderException("Failed to obtain AES AlgorithmParameters", e);
        } catch (InvalidParameterSpecException e) {
            throw new ProviderException("Failed to initialize AES AlgorithmParameters with an IV", e);
        }
    }
    return null;
}
Also used : ProviderException(java.security.ProviderException) IvParameterSpec(javax.crypto.spec.IvParameterSpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) AlgorithmParameters(java.security.AlgorithmParameters) Nullable(android.annotation.Nullable)

Example 13 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project j2objc by google.

the class AlgorithmParametersTest method test_initLjava_security_spec_AlgorithmParameterSpec.

/**
     * java.security.AlgorithmParameters#init(java.security.spec.AlgorithmParameterSpec)
     */
public void test_initLjava_security_spec_AlgorithmParameterSpec() throws Exception {
    //
    // test: corresponding spi method is invoked
    //
    final MyAlgorithmParameterSpec spec = new MyAlgorithmParameterSpec();
    MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {

        protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {
            assertSame(spec, paramSpec);
            runEngineInit_AlgParamSpec = true;
        }
    };
    AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
    params.init(spec);
    assertTrue(paramSpi.runEngineInit_AlgParamSpec);
    //
    try {
        params.init(spec);
        fail("No expected InvalidParameterSpecException");
    } catch (InvalidParameterSpecException e) {
    // expected
    }
    params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
    params.init(new byte[0]);
    try {
        params.init(spec);
        fail("No expected InvalidParameterSpecException");
    } catch (InvalidParameterSpecException e) {
    // expected
    }
    params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
    params.init(new byte[0], "format");
    try {
        params.init(spec);
        fail("No expected InvalidParameterSpecException");
    } catch (InvalidParameterSpecException e) {
    // expected
    }
    //
    // test: if paramSpec is null
    //
    paramSpi = new MyAlgorithmParameters() {

        protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {
            // null is passed to spi-provider
            assertNull(paramSpec);
            runEngineInit_AlgParamSpec = true;
        }
    };
    params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
    params.init((AlgorithmParameterSpec) null);
    assertTrue(paramSpi.runEngineInit_AlgParamSpec);
}
Also used : InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) AlgorithmParameters(java.security.AlgorithmParameters)

Example 14 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project j2objc by google.

the class AlgorithmParametersTest method test_getParameterSpecLjava_lang_Class.

/**
     * java.security.AlgorithmParameters#getParameterSpec(Class)
     */
public void test_getParameterSpecLjava_lang_Class() throws Exception {
    final MyAlgorithmParameterSpec myParamSpec = new MyAlgorithmParameterSpec();
    MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {

        protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec) {
            return myParamSpec;
        }
    };
    AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
    //
    try {
        params.getParameterSpec(null);
        fail("No expected InvalidParameterSpecException");
    } catch (InvalidParameterSpecException e) {
    // expected
    }
    try {
        params.getParameterSpec(MyAlgorithmParameterSpec.class);
        fail("No expected InvalidParameterSpecException");
    } catch (InvalidParameterSpecException e) {
    // expected
    }
    //
    // test: corresponding spi method is invoked
    //
    params.init(new MyAlgorithmParameterSpec());
    assertSame(myParamSpec, params.getParameterSpec(MyAlgorithmParameterSpec.class));
    //
    // test: if paramSpec is null
    // Regression test for HARMONY-2733
    //
    paramSpi = new MyAlgorithmParameters() {

        protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec) {
            // null is passed to spi-provider
            assertNull(paramSpec);
            return null;
        }
    };
    params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
    params.init(new MyAlgorithmParameterSpec());
    assertNull(params.getParameterSpec(null));
}
Also used : InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) AlgorithmParameters(java.security.AlgorithmParameters)

Example 15 with InvalidParameterSpecException

use of java.security.spec.InvalidParameterSpecException in project robovm by robovm.

the class OpenSSLCipher method engineInit.

@Override
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
    final AlgorithmParameterSpec spec;
    try {
        spec = params.getParameterSpec(IvParameterSpec.class);
    } catch (InvalidParameterSpecException e) {
        throw new InvalidAlgorithmParameterException(e);
    }
    engineInit(opmode, key, spec, random);
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) IvParameterSpec(javax.crypto.spec.IvParameterSpec) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Aggregations

InvalidParameterSpecException (java.security.spec.InvalidParameterSpecException)54 AlgorithmParameters (java.security.AlgorithmParameters)19 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)15 IvParameterSpec (javax.crypto.spec.IvParameterSpec)14 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)11 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)11 InvalidKeyException (java.security.InvalidKeyException)6 DSAParameterSpec (java.security.spec.DSAParameterSpec)6 OAEPParameterSpec (javax.crypto.spec.OAEPParameterSpec)6 Nullable (android.annotation.Nullable)5 ProviderException (java.security.ProviderException)5 DSAParams (java.security.interfaces.DSAParams)4 BadPaddingException (javax.crypto.BadPaddingException)4 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)4 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)4 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 BigInteger (java.math.BigInteger)3 NoSuchProviderException (java.security.NoSuchProviderException)3 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)3