Search in sources :

Example 81 with Signature

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

the class Signature2Test method test_initSignLjava_security_PrivateKeyLjava_security_SecureRandom_mismatch.

public void test_initSignLjava_security_PrivateKeyLjava_security_SecureRandom_mismatch() throws Exception {
    try {
        Signature sig = Signature.getInstance("DSA");
        sig.initSign(getRsaKeys().getPrivate(), new SecureRandom());
        fail();
    } catch (InvalidKeyException expected) {
    }
}
Also used : Signature(java.security.Signature) SecureRandom(java.security.SecureRandom) InvalidKeyException(java.security.InvalidKeyException)

Example 82 with Signature

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

the class Signature2Test method test_verify$B.

/**
     * java.security.Signature#verify(byte[])
     */
public void test_verify$B() throws Exception {
    Signature sig = Signature.getInstance("DSA");
    try {
        sig.verify(new byte[] { 0, 1, 2, 3 });
        fail();
    } catch (SignatureException expected) {
    }
    sig.initSign(getDsaKeys().getPrivate());
    sig.update(MESSAGE.getBytes());
    byte[] signature = sig.sign();
    sig.initVerify(getDsaKeys().getPublic());
    sig.update(MESSAGE.getBytes());
    assertTrue("Sign/Verify does not pass", sig.verify(signature));
}
Also used : Signature(java.security.Signature) SignatureException(java.security.SignatureException)

Example 83 with Signature

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

the class Signature2Test method test_getInstanceLjava_lang_StringLjava_lang_String_java_security_Provider.

/**
     * java.security.Signature#getInstance(java.lang.String,
     *        java.security.Provider)
     */
public void test_getInstanceLjava_lang_StringLjava_lang_String_java_security_Provider() throws Exception {
    Provider[] providers = Security.getProviders("Signature.DSA");
    for (int i = 0; i < providers.length; i++) {
        Signature signature = Signature.getInstance("DSA", providers[i]);
        assertEquals("DSA", signature.getAlgorithm());
        assertEquals(providers[i], signature.getProvider());
    }
    try {
        Signature.getInstance((String) null, (Provider) null);
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        Signature.getInstance("DSA", (Provider) null);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    try {
        Signature.getInstance((String) null, providers[0]);
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        Signature.getInstance("bogus", providers[0]);
        fail();
    } catch (NoSuchAlgorithmException expected) {
    }
}
Also used : Signature(java.security.Signature) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Provider(java.security.Provider)

Example 84 with Signature

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

the class Signature2Test method test_initSignLjava_security_PrivateKeyLjava_security_SecureRandom.

public void test_initSignLjava_security_PrivateKeyLjava_security_SecureRandom() throws Exception {
    Signature sig = Signature.getInstance("DSA");
    sig.initSign(getDsaKeys().getPrivate(), new SecureRandom());
}
Also used : Signature(java.security.Signature) SecureRandom(java.security.SecureRandom)

Example 85 with Signature

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

the class Signature2Test method test_getParameterLjava_lang_String.

/**
     * java.security.Signature#getParameter(java.lang.String)
     */
@SuppressWarnings("deprecation")
public void test_getParameterLjava_lang_String() throws Exception {
    Signature sig = Signature.getInstance("DSA");
    try {
        sig.getParameter("r");
        sig.getParameter("s");
    } catch (UnsupportedOperationException e) {
    }
}
Also used : Signature(java.security.Signature)

Aggregations

Signature (java.security.Signature)261 SignatureException (java.security.SignatureException)84 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)70 InvalidKeyException (java.security.InvalidKeyException)61 PublicKey (java.security.PublicKey)61 PrivateKey (java.security.PrivateKey)43 IOException (java.io.IOException)42 KeyFactory (java.security.KeyFactory)41 X509Certificate (java.security.cert.X509Certificate)26 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)23 KeyPair (java.security.KeyPair)19 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)19 GeneralSecurityException (java.security.GeneralSecurityException)16 KeyPairGenerator (java.security.KeyPairGenerator)16 MySignature1 (org.apache.harmony.security.tests.support.MySignature1)16 ByteArrayInputStream (java.io.ByteArrayInputStream)14 BigInteger (java.math.BigInteger)14 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)14 CertificateException (java.security.cert.CertificateException)14 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)14