Search in sources :

Example 11 with AlgorithmParameters

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

the class AlgorithmParameterGeneratorTest method testAlgorithmParameterGenerator.

public void testAlgorithmParameterGenerator() {
    AlgorithmParameterGenerator generator = null;
    try {
        generator = AlgorithmParameterGenerator.getInstance(algorithmName);
    } catch (NoSuchAlgorithmException e) {
        fail(e.getMessage());
    }
    generator.init(1024);
    AlgorithmParameters parameters = generator.generateParameters();
    assertNotNull("generated parameters are null", parameters);
    helper.test(parameters);
}
Also used : AlgorithmParameterGenerator(java.security.AlgorithmParameterGenerator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 12 with AlgorithmParameters

use of java.security.AlgorithmParameters 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 13 with AlgorithmParameters

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

the class OpenSSLCipher method engineGetParameters.

@Override
protected AlgorithmParameters engineGetParameters() {
    if (iv != null && iv.length > 0) {
        try {
            AlgorithmParameters params = AlgorithmParameters.getInstance(getBaseCipherName());
            params.init(iv);
            return params;
        } catch (NoSuchAlgorithmException e) {
            return null;
        } catch (IOException e) {
            return null;
        }
    }
    return null;
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 14 with AlgorithmParameters

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

the class ExemptionMechanismSpiTest method testExemptionMechanismSpi01.

/**
     * Test for <code>ExemptionMechanismSpi</code> constructor Assertion:
     * constructs ExemptionMechanismSpi
     * @throws Exception
     */
public void testExemptionMechanismSpi01() throws Exception {
    Mock_ExemptionMechanismSpi emSpi = new Mock_ExemptionMechanismSpi() {
    };
    int len = MyExemptionMechanismSpi.getLength();
    byte[] bbRes = emSpi.engineGenExemptionBlob();
    assertEquals("Incorrect length", bbRes.length, len);
    assertEquals("Incorrect result", emSpi.engineGenExemptionBlob(new byte[1], len), len);
    assertEquals("Incorrect output size", 10, emSpi.engineGetOutputSize(100));
    Key key = null;
    AlgorithmParameters params = null;
    AlgorithmParameterSpec parSpec = null;
    try {
        emSpi.engineInit(key);
        fail("InvalidKeyException must be thrown");
    } catch (InvalidKeyException e) {
    }
    try {
        emSpi.engineInit(key, params);
        fail("InvalidKeyException must be thrown");
    } catch (InvalidKeyException e) {
    }
    try {
        emSpi.engineInit(key, parSpec);
        fail("InvalidKeyException must be thrown");
    } catch (InvalidKeyException e) {
    }
    key = ((MyExemptionMechanismSpi) emSpi).new tmp1Key("Proba", new byte[0]);
    try {
        emSpi.engineInit(key);
        fail("ExemptionMechanismException must be thrown");
    } catch (ExemptionMechanismException e) {
    }
    try {
        emSpi.engineInit(key, params);
        fail("ExemptionMechanismException must be thrown");
    } catch (ExemptionMechanismException e) {
    }
    try {
        emSpi.engineInit(key, parSpec);
        fail("ExemptionMechanismException must be thrown");
    } catch (ExemptionMechanismException e) {
    }
    key = ((MyExemptionMechanismSpi) emSpi).new tmpKey("Proba", new byte[0]);
    emSpi.engineInit(key);
    emSpi.engineInit(key, AlgorithmParameters.getInstance("DH"));
    emSpi.engineInit(key, new RSAKeyGenParameterSpec(10, new BigInteger("10")));
    assertEquals("Incorrect result", 10, emSpi.engineGetOutputSize(100));
}
Also used : RSAKeyGenParameterSpec(java.security.spec.RSAKeyGenParameterSpec) BigInteger(java.math.BigInteger) InvalidKeyException(java.security.InvalidKeyException) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) ExemptionMechanismException(javax.crypto.ExemptionMechanismException) Key(java.security.Key) AlgorithmParameters(java.security.AlgorithmParameters)

Example 15 with AlgorithmParameters

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

the class EncryptedPrivateKeyInfoTest method testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray2.

/**
     * Test #2 for
     * <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[])
     * </code>
     * constructor <br>
     * Assertion: <code>NullPointerException</code>- if the specified
     * algorithm parameters or encrypted data is <code>null</code><br>
     * Test preconditions: pass <code>null</code> as algorithm parameters then
     * as encrypted data <br>
     * Expected: <code>NullPointerException</code> in both cases
     *
     * @throws NoSuchAlgorithmException
     * @throws IOException
     */
public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray2() throws NoSuchAlgorithmException, IOException {
    // 1: pass null as AlgorithmParameters
    try {
        new EncryptedPrivateKeyInfo((AlgorithmParameters) null, EncryptedPrivateKeyInfoData.encryptedData);
        fail(getName() + ": NullPointerException has not been thrown");
    } catch (NullPointerException ok) {
    }
    // 2: pass null as encrypted data
    try {
        AlgorithmParameters ap = AlgorithmParameters.getInstance("DSA");
        // use pregenerated AlgorithmParameters encodings
        ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding("DSA"));
        new EncryptedPrivateKeyInfo(ap, null);
        fail(getName() + ": NullPointerException has not been thrown");
    } catch (NullPointerException ok) {
    }
}
Also used : EncryptedPrivateKeyInfo(javax.crypto.EncryptedPrivateKeyInfo) 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