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);
}
}
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());
}
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());
}
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());
}
}
use of javax.crypto.BadPaddingException in project Signal-Android by WhisperSystems.
the class DecryptingPartInputStream method readFinal.
private int readFinal(byte[] buffer, int offset, int length) throws IOException {
try {
int flourish = cipher.doFinal(buffer, offset);
//mac.update(buffer, offset, flourish);
byte[] ourMac = mac.doFinal();
byte[] theirMac = new byte[mac.getMacLength()];
readFully(theirMac);
if (!Arrays.equals(ourMac, theirMac))
throw new IOException("MAC doesn't match! Potential tampering?");
done = true;
return flourish;
} catch (IllegalBlockSizeException e) {
Log.w(TAG, e);
throw new IOException("Illegal block size exception!");
} catch (ShortBufferException e) {
Log.w(TAG, e);
throw new IOException("Short buffer exception!");
} catch (BadPaddingException e) {
Log.w(TAG, e);
throw new IOException("Bad padding exception!");
}
}
Aggregations