Search in sources :

Example 6 with IllegalBlockSizeException

use of javax.crypto.IllegalBlockSizeException in project robovm by robovm.

the class IllegalBlockSizeExceptionTest method testIllegalBlockSizeException01.

/**
     * Test for <code>IllegalBlockSizeException()</code> constructor
     * Assertion: constructs IllegalBlockSizeException with no detail message
     */
public void testIllegalBlockSizeException01() {
    IllegalBlockSizeException tE = new IllegalBlockSizeException();
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException)

Example 7 with IllegalBlockSizeException

use of javax.crypto.IllegalBlockSizeException in project robovm by robovm.

the class IllegalBlockSizeExceptionTest method testIllegalBlockSizeException02.

/**
     * Test for <code>IllegalBlockSizeException(String)</code> constructor
     * Assertion: constructs IllegalBlockSizeException with detail message msg.
     * Parameter <code>msg</code> is not null.
     */
public void testIllegalBlockSizeException02() {
    IllegalBlockSizeException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new IllegalBlockSizeException(msgs[i]);
        assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", tE.getCause());
    }
}
Also used : IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException)

Example 8 with IllegalBlockSizeException

use of javax.crypto.IllegalBlockSizeException in project robovm by robovm.

the class CipherTest method test_doFinal$B.

public void test_doFinal$B() throws Exception {
    byte[] b1 = new byte[32];
    byte[] bI1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    byte[] bI2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
    byte[] bI3 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
    byte[] bI4 = { 1, 2, 3 };
    AlgorithmParameterSpec ap = new IvParameterSpec(IV);
    Cipher c = Cipher.getInstance("DES/CBC/NoPadding");
    c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_DES, ap);
    try {
        c.doFinal(bI1);
        fail();
    } catch (IllegalBlockSizeException expected) {
    }
    c = Cipher.getInstance("DES/CBC/NoPadding");
    try {
        c.doFinal(bI1);
        fail();
    } catch (IllegalStateException expected) {
    }
    c = Cipher.getInstance("DES/CBC/NoPadding");
    c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_DES, ap);
    int len1 = c.doFinal(bI2).length;
    assertEquals(16, len1);
    c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_DES, ap);
    int len2 = c.doFinal(bI3, 0, 16, b1, 0);
    assertEquals(16, len2);
    c = Cipher.getInstance("DES/CBC/PKCS5Padding");
    c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_DES, ap);
    try {
        c.doFinal(b1);
        fail();
    } catch (BadPaddingException expected) {
    }
}
Also used : IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) MyCipher(org.apache.harmony.crypto.tests.support.MyCipher) BadPaddingException(javax.crypto.BadPaddingException) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Example 9 with IllegalBlockSizeException

use of javax.crypto.IllegalBlockSizeException in project robovm by robovm.

the class CipherTest method test_wrap_java_security_Key.

public void test_wrap_java_security_Key() throws Exception {
    AlgorithmParameterSpec ap = new IvParameterSpec(IV);
    Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding");
    c.init(Cipher.WRAP_MODE, CIPHER_KEY_DES, ap, new SecureRandom());
    assertNotNull(c.wrap(CIPHER_KEY_DES));
    assertNotNull(c.wrap(CIPHER_KEY_3DES));
    String certName = Support_Resources.getURL("test.cert");
    InputStream is = new URL(certName).openConnection().getInputStream();
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    Certificate cert = cf.generateCertificate(is);
    assertNotNull(c.wrap(cert.getPublicKey()));
    c = Cipher.getInstance("DES/CBC/NoPadding");
    c.init(Cipher.WRAP_MODE, CIPHER_KEY_DES, ap, new SecureRandom());
    try {
        assertNotNull(c.wrap(cert.getPublicKey()));
        fail();
    } catch (IllegalBlockSizeException expected) {
    }
    c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_DES, ap, new SecureRandom());
    try {
        c.wrap(CIPHER_KEY_DES);
        fail();
    } catch (IllegalStateException expected) {
    }
    c.init(Cipher.WRAP_MODE, CIPHER_KEY_DES, ap, new SecureRandom());
    try {
        c.wrap(new Mock_Key());
        fail();
    } catch (InvalidKeyException expected) {
    }
}
Also used : InputStream(java.io.InputStream) SecureRandom(java.security.SecureRandom) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) InvalidKeyException(java.security.InvalidKeyException) CertificateFactory(java.security.cert.CertificateFactory) URL(java.net.URL) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) MyCipher(org.apache.harmony.crypto.tests.support.MyCipher) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) Certificate(java.security.cert.Certificate)

Example 10 with IllegalBlockSizeException

use of javax.crypto.IllegalBlockSizeException in project robovm by robovm.

the class CipherTest method testDoFinalbyteArrayintintbyteArrayint.

/*
     * Class under test for int doFinal(byte[], int, int, byte[], int)
     */
public void testDoFinalbyteArrayintintbyteArrayint() throws Exception {
    byte[] b = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
    byte[] b1 = new byte[30];
    AlgorithmParameterSpec ap = new IvParameterSpec(IV);
    Cipher c = Cipher.getInstance("DES/CBC/NoPadding");
    c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_DES, ap);
    try {
        c.doFinal(b, 0, 10, b1, 5);
        fail();
    } catch (IllegalBlockSizeException expected) {
    }
    c = Cipher.getInstance("DES/CBC/NoPadding");
    try {
        c.doFinal(b, 0, 10, b1, 5);
        fail();
    } catch (IllegalStateException expected) {
    }
    c = Cipher.getInstance("DES/CBC/NoPadding");
    c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_DES, ap);
    int len = c.doFinal(b, 0, 16, b1, 0);
    assertEquals(16, len);
    c = Cipher.getInstance("DES/CBC/PKCS5Padding");
    c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_DES, ap);
    try {
        c.doFinal(b1, 0, 24, new byte[42], 0);
        fail();
    } catch (BadPaddingException expected) {
    }
    b1 = new byte[6];
    c = Cipher.getInstance("DESede");
    c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_3DES);
    try {
        c.doFinal(b, 3, 6, b1, 5);
        fail();
    } catch (IllegalBlockSizeException maybeExpected) {
        assertTrue(StandardNames.IS_RI);
    } catch (ShortBufferException maybeExpected) {
        assertFalse(StandardNames.IS_RI);
    }
}
Also used : IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) ShortBufferException(javax.crypto.ShortBufferException) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) MyCipher(org.apache.harmony.crypto.tests.support.MyCipher) BadPaddingException(javax.crypto.BadPaddingException) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Aggregations

IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)110 BadPaddingException (javax.crypto.BadPaddingException)95 InvalidKeyException (java.security.InvalidKeyException)77 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)66 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)65 Cipher (javax.crypto.Cipher)54 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)45 IOException (java.io.IOException)38 SecretKey (javax.crypto.SecretKey)26 IvParameterSpec (javax.crypto.spec.IvParameterSpec)26 UnrecoverableKeyException (java.security.UnrecoverableKeyException)25 CertificateException (java.security.cert.CertificateException)25 KeyStoreException (java.security.KeyStoreException)24 SecretKeySpec (javax.crypto.spec.SecretKeySpec)23 RemoteException (android.os.RemoteException)15 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)15 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)13 KeyGenerator (javax.crypto.KeyGenerator)13 ShortBufferException (javax.crypto.ShortBufferException)13 UnsupportedEncodingException (java.io.UnsupportedEncodingException)11