Search in sources :

Example 1 with AlgorithmParameters

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

the class JCEStreamCipher method engineGetParameters.

protected AlgorithmParameters engineGetParameters() {
    if (engineParams == null) {
        if (pbeSpec != null) {
            try {
                AlgorithmParameters engineParams = AlgorithmParameters.getInstance(pbeAlgorithm, BouncyCastleProvider.PROVIDER_NAME);
                engineParams.init(pbeSpec);
                return engineParams;
            } catch (Exception e) {
                return null;
            }
        }
    }
    return engineParams;
}
Also used : InvalidKeySpecException(java.security.spec.InvalidKeySpecException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) DataLengthException(org.bouncycastle.crypto.DataLengthException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) ShortBufferException(javax.crypto.ShortBufferException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) BadPaddingException(javax.crypto.BadPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 2 with AlgorithmParameters

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

the class myAlgPG method testAlgorithmParameterGenerator10.

/**
     * Test for <code>generateParameters()</code> method
     * Assertion: returns AlgorithmParameters object
     */
public void testAlgorithmParameterGenerator10() throws NoSuchAlgorithmException {
    if (!DSASupported) {
        fail(validAlgName + " algorithm is not supported");
        return;
    }
    AlgorithmParameterGenerator apg = AlgorithmParameterGenerator.getInstance(validAlgName);
    apg.init(512);
    AlgorithmParameters ap = apg.generateParameters();
    assertEquals("Incorrect algorithm", ap.getAlgorithm().toUpperCase(), apg.getAlgorithm().toUpperCase());
}
Also used : AlgorithmParameterGenerator(java.security.AlgorithmParameterGenerator) AlgorithmParameters(java.security.AlgorithmParameters)

Example 3 with AlgorithmParameters

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

the class AlgorithmParameterGenerator2Test method checkResult.

private void checkResult(AlgorithmParameterGenerator algParGen) throws InvalidAlgorithmParameterException {
    AlgorithmParameters param = algParGen.generateParameters();
    assertNull("Not null parameters", param);
    AlgorithmParameterSpec pp = null;
    algParGen.init(pp, new SecureRandom());
    algParGen.init(pp);
    try {
        algParGen.init(pp, null);
        fail("IllegalArgumentException must be thrown");
    } catch (IllegalArgumentException e) {
    }
    pp = new tmpAlgorithmParameterSpec("Proba");
    algParGen.init(pp, new SecureRandom());
    algParGen.init(pp);
    algParGen.init(0, null);
    algParGen.init(0, new SecureRandom());
    try {
        algParGen.init(-10, null);
        fail("IllegalArgumentException must be thrown");
    } catch (IllegalArgumentException e) {
    }
    try {
        algParGen.init(-10, new SecureRandom());
        fail("IllegalArgumentException must be thrown");
    } catch (IllegalArgumentException e) {
    }
}
Also used : SecureRandom(java.security.SecureRandom) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) AlgorithmParameters(java.security.AlgorithmParameters)

Example 4 with AlgorithmParameters

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

the class AlgorithmParametersTest method testOAEPProvider.

/**
     * Tests OAEP AlgorithmParameters provider
     */
public void testOAEPProvider() throws Exception {
    AlgorithmParameters params = AlgorithmParameters.getInstance("OAEP");
    assertEquals("Algorithm", "OAEP", params.getAlgorithm());
}
Also used : AlgorithmParameters(java.security.AlgorithmParameters)

Example 5 with AlgorithmParameters

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

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)

Aggregations

AlgorithmParameters (java.security.AlgorithmParameters)107 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)39 IOException (java.io.IOException)31 InvalidParameterSpecException (java.security.spec.InvalidParameterSpecException)22 Cipher (javax.crypto.Cipher)22 SecretKey (javax.crypto.SecretKey)18 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)13 NoSuchProviderException (java.security.NoSuchProviderException)12 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)11 Key (java.security.Key)11 SecureRandom (java.security.SecureRandom)10 EncryptedPrivateKeyInfo (javax.crypto.EncryptedPrivateKeyInfo)10 InvalidKeyException (java.security.InvalidKeyException)8 PBEParameterSpec (javax.crypto.spec.PBEParameterSpec)8 UnrecoverableKeyException (java.security.UnrecoverableKeyException)7 KeyPair (java.security.KeyPair)6 KeyPairGenerator (java.security.KeyPairGenerator)6 AlgorithmId (sun.security.x509.AlgorithmId)6 Nullable (android.annotation.Nullable)5 Asn1Integer (com.android.hotspot2.asn1.Asn1Integer)5