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());
}
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());
}
}
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) {
}
}
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) {
}
}
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);
}
}
Aggregations