Search in sources :

Example 6 with BadPaddingException

use of javax.crypto.BadPaddingException 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)

Example 7 with BadPaddingException

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

the class BadPaddingExceptionTest method testBadPaddingException03.

/**
     * Test for <code>BadPaddingException(String)</code> constructor
     * Assertion: constructs BadPaddingException when <code>msg</code> is null
     */
public void testBadPaddingException03() {
    String msg = null;
    BadPaddingException tE = new BadPaddingException(msg);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : BadPaddingException(javax.crypto.BadPaddingException)

Example 8 with BadPaddingException

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

the class BadPaddingExceptionTest method testBadPaddingException01.

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

Example 9 with BadPaddingException

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

the class BadPaddingExceptionTest method testBadPaddingException02.

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

Example 10 with BadPaddingException

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

the class CipherTest method test_doFinal$BII.

public void test_doFinal$BII() 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);
        fail();
    } catch (IllegalBlockSizeException expected) {
    }
    c = Cipher.getInstance("DES/CBC/NoPadding");
    try {
        c.doFinal(b, 0, 10);
        fail();
    } catch (IllegalStateException expected) {
    }
    c = Cipher.getInstance("DES/CBC/NoPadding");
    c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_DES, ap);
    int len1 = c.doFinal(b, 0, 16).length;
    assertEquals(16, len1);
    c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_DES, ap);
    int len2 = c.doFinal(b, 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, 0, 24);
        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)

Aggregations

BadPaddingException (javax.crypto.BadPaddingException)110 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)95 InvalidKeyException (java.security.InvalidKeyException)74 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)66 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)65 Cipher (javax.crypto.Cipher)47 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)44 IOException (java.io.IOException)37 KeyStoreException (java.security.KeyStoreException)25 UnrecoverableKeyException (java.security.UnrecoverableKeyException)25 CertificateException (java.security.cert.CertificateException)25 SecretKey (javax.crypto.SecretKey)25 IvParameterSpec (javax.crypto.spec.IvParameterSpec)24 SecretKeySpec (javax.crypto.spec.SecretKeySpec)21 RemoteException (android.os.RemoteException)15 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)15 KeyGenerator (javax.crypto.KeyGenerator)13 ShortBufferException (javax.crypto.ShortBufferException)13 FileNotFoundException (java.io.FileNotFoundException)11 UnsupportedEncodingException (java.io.UnsupportedEncodingException)11