Search in sources :

Example 56 with NoSuchAlgorithmException

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

the class SignatureTest method testInitVerifyCertificate.

/*
     * Class under test for void initVerify(Certificate)
     */
public void testInitVerifyCertificate() throws InvalidKeyException {
    MySignature1 s = new MySignature1("ABC");
    s.initVerify(new MyCertificate());
    assertEquals("state", MySignature1.VERIFY, s.getState());
    assertTrue("initVerify() failed", s.runEngineInitVerify);
    try {
        Signature sig = getTestSignature();
        sig.initVerify(new MyCertificate());
        fail("expected InvalidKeyException");
    } catch (InvalidKeyException e) {
    // ok
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected : " + e);
    }
}
Also used : Signature(java.security.Signature) MySignature1(org.apache.harmony.security.tests.support.MySignature1) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException)

Example 57 with NoSuchAlgorithmException

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

the class SignatureTest method testInitSignPrivateKey.

/*
     * Class under test for void initSign(PrivateKey)
     */
public void testInitSignPrivateKey() throws InvalidKeyException {
    MySignature1 s = new MySignature1("ABC");
    s.initSign(new MyPrivateKey());
    assertEquals("state", MySignature1.SIGN, s.getState());
    assertTrue("initSign() failed", s.runEngineInitSign);
    try {
        Signature signature = getTestSignature();
        signature.initSign(null);
        fail("expected InvalidKeyException");
    } catch (InvalidKeyException e) {
    // ok
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected: " + e);
    }
}
Also used : Signature(java.security.Signature) MySignature1(org.apache.harmony.security.tests.support.MySignature1) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException)

Example 58 with NoSuchAlgorithmException

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

the class SignatureTest method testInitVerifyPublicKey.

/*
     * Class under test for void initVerify(PublicKey)
     */
public void testInitVerifyPublicKey() throws InvalidKeyException {
    MySignature1 s = new MySignature1("ABC");
    s.initVerify(new MyPublicKey());
    assertEquals("state", MySignature1.VERIFY, s.getState());
    assertTrue("initVerify() failed", s.runEngineInitVerify);
    try {
        Signature sig = getTestSignature();
        sig.initVerify((PublicKey) null);
    } catch (InvalidKeyException e) {
    // ok
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected : " + e);
    }
}
Also used : Signature(java.security.Signature) MySignature1(org.apache.harmony.security.tests.support.MySignature1) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException)

Example 59 with NoSuchAlgorithmException

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

the class SignatureTest method testInitSignPrivateKeySecureRandom.

/*
     * Class under test for void initSign(PrivateKey, SecureRandom)
     */
public void testInitSignPrivateKeySecureRandom() throws InvalidKeyException {
    MySignature1 s = new MySignature1("ABC");
    s.initSign(new MyPrivateKey(), new SecureRandom());
    assertEquals("state", MySignature1.SIGN, s.getState());
    assertTrue("initSign() failed", s.runEngineInitSign);
    try {
        Signature sig = getTestSignature();
        sig.initSign(null, null);
        fail("expected InvalidKeyException");
    } catch (InvalidKeyException e) {
    // ok
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected : " + e);
    }
}
Also used : Signature(java.security.Signature) SecureRandom(java.security.SecureRandom) MySignature1(org.apache.harmony.security.tests.support.MySignature1) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException)

Example 60 with NoSuchAlgorithmException

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

the class AlgorithmParametersTest method test_getInstanceLjava_lang_StringLjava_security_Provider.

/**
     * java.security.AlgorithmParameters#getInstance(String, Provider)
     */
public void test_getInstanceLjava_lang_StringLjava_security_Provider() {
    String[] alg = { "", "qwertyu", "!@#$%^&*()" };
    Provider pp = null;
    try {
        AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", p);
        checkUnititialized(ap);
        ap.init(new byte[6], "aaa");
        checkAP(ap, p);
    } catch (Exception e) {
        fail("Unexpected exception");
    }
    for (int i = 0; i < alg.length; i++) {
        try {
            AlgorithmParameters ap = AlgorithmParameters.getInstance(alg[i], p);
            fail("NoSuchAlgorithmException was not thrown for parameter " + alg[i]);
        } catch (NoSuchAlgorithmException nsae) {
        //expected
        } catch (Exception e) {
            fail("Incorrect exception " + e + " was thrown for " + alg[i]);
        }
    }
    try {
        AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", pp);
        fail("IllegalArgumentException was not thrown for NULL provider");
    } catch (IllegalArgumentException iae) {
    //expected
    } catch (Exception e) {
        fail("Incorrect exception " + e + " was thrown");
    }
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) NoSuchProviderException(java.security.NoSuchProviderException) Provider(java.security.Provider) AlgorithmParameters(java.security.AlgorithmParameters)

Aggregations

NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1557 MessageDigest (java.security.MessageDigest)590 IOException (java.io.IOException)374 InvalidKeyException (java.security.InvalidKeyException)266 KeyStoreException (java.security.KeyStoreException)200 CertificateException (java.security.cert.CertificateException)163 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)162 UnsupportedEncodingException (java.io.UnsupportedEncodingException)141 KeyManagementException (java.security.KeyManagementException)130 KeyFactory (java.security.KeyFactory)105 NoSuchProviderException (java.security.NoSuchProviderException)102 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)96 SSLContext (javax.net.ssl.SSLContext)91 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)90 KeyStore (java.security.KeyStore)89 UnrecoverableKeyException (java.security.UnrecoverableKeyException)88 InputStream (java.io.InputStream)82 SecureRandom (java.security.SecureRandom)82 Cipher (javax.crypto.Cipher)79 BadPaddingException (javax.crypto.BadPaddingException)75