Search in sources :

Example 56 with AlgorithmParameters

use of java.security.AlgorithmParameters in project j2objc by google.

the class AlgorithmParametersTest method test_getEncoded.

/**
     * java.security.AlgorithmParameters#getEncoded()
     */
public void test_getEncoded() throws Exception {
    final byte[] enc = new byte[] { 0x02, 0x01, 0x03 };
    MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {

        protected byte[] engineGetEncoded() throws IOException {
            return enc;
        }
    };
    AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
    //
    try {
        params.getEncoded();
        fail("should not get encoded from un-initialized instance");
    } catch (IOException e) {
    // expected
    }
    //
    // test: corresponding spi method is invoked
    //
    params.init(new MyAlgorithmParameterSpec());
    assertSame(enc, params.getEncoded());
}
Also used : IOException(java.io.IOException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 57 with AlgorithmParameters

use of java.security.AlgorithmParameters in project j2objc by google.

the class AlgorithmParametersTest method test_getAlgorithm.

/**
     * java.security.AlgorithmParameters#getAlgorithm()
     */
public void test_getAlgorithm() throws Exception {
    // test: null value
    AlgorithmParameters ap = new DummyAlgorithmParameters(null, p, null);
    assertNull(ap.getAlgorithm());
    // test: not null value
    ap = new DummyAlgorithmParameters(null, p, "AAA");
    assertEquals("AAA", ap.getAlgorithm());
}
Also used : AlgorithmParameters(java.security.AlgorithmParameters)

Example 58 with AlgorithmParameters

use of java.security.AlgorithmParameters in project j2objc by google.

the class AlgorithmParameterGeneratorSpiTest method testAlgorithmParameterGeneratorSpi01.

/**
     * Test for <code>AlgorithmParameterGeneratorSpi</code> constructor
     * Assertion: constructs AlgorithmParameterGeneratorSpi
     */
public void testAlgorithmParameterGeneratorSpi01() throws InvalidAlgorithmParameterException {
    MyAlgorithmParameterGeneratorSpi algParGen = new MyAlgorithmParameterGeneratorSpi();
    AlgorithmParameters param = algParGen.engineGenerateParameters();
    assertNull("Not null parameters", param);
    AlgorithmParameterSpec pp = null;
    algParGen.engineInit(pp, new SecureRandom());
    try {
        algParGen.engineInit(pp, null);
        fail("IllegalArgumentException must be thrown");
    } catch (IllegalArgumentException e) {
    }
    algParGen.engineInit(0, null);
    algParGen.engineInit(0, new SecureRandom());
    try {
        algParGen.engineInit(-10, null);
        fail("IllegalArgumentException must be thrown");
    } catch (IllegalArgumentException e) {
    }
    try {
        algParGen.engineInit(-10, new SecureRandom());
        fail("IllegalArgumentException must be thrown");
    } catch (IllegalArgumentException e) {
    }
}
Also used : MyAlgorithmParameterGeneratorSpi(org.apache.harmony.security.tests.support.MyAlgorithmParameterGeneratorSpi) SecureRandom(java.security.SecureRandom) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) AlgorithmParameters(java.security.AlgorithmParameters)

Example 59 with AlgorithmParameters

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

the class OpenSslEngineTest method testAlgorithmConstraintsThrows.

@Test(expected = IllegalArgumentException.class)
public void testAlgorithmConstraintsThrows() throws Exception {
    SelfSignedCertificate ssc = new SelfSignedCertificate();
    serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).sslProvider(sslServerProvider()).build();
    SSLEngine engine = serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT);
    try {
        SSLParameters parameters = new SSLParameters();
        parameters.setAlgorithmConstraints(new AlgorithmConstraints() {

            @Override
            public boolean permits(Set<CryptoPrimitive> primitives, String algorithm, AlgorithmParameters parameters) {
                return false;
            }

            @Override
            public boolean permits(Set<CryptoPrimitive> primitives, Key key) {
                return false;
            }

            @Override
            public boolean permits(Set<CryptoPrimitive> primitives, String algorithm, Key key, AlgorithmParameters parameters) {
                return false;
            }
        });
        engine.setSSLParameters(parameters);
    } finally {
        cleanupServerSslEngine(engine);
        ssc.delete();
    }
}
Also used : SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) CryptoPrimitive(java.security.CryptoPrimitive) SSLParameters(javax.net.ssl.SSLParameters) SSLEngine(javax.net.ssl.SSLEngine) Key(java.security.Key) AlgorithmConstraints(java.security.AlgorithmConstraints) AlgorithmParameters(java.security.AlgorithmParameters) Test(org.junit.Test)

Example 60 with AlgorithmParameters

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

the class BaseStreamCipher 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 : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) DataLengthException(org.bouncycastle.crypto.DataLengthException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) InvalidKeyException(java.security.InvalidKeyException) ShortBufferException(javax.crypto.ShortBufferException) 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