use of javax.crypto.Cipher in project robovm by robovm.
the class CipherTest method test_initWithSecureRandom.
/**
* javax.crypto.Cipher#init(int, java.security.Key,
* java.security.SecureRandom)
*/
public void test_initWithSecureRandom() throws Exception {
Cipher cipher = Cipher.getInstance(ALGORITHM_3DES + "/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_3DES, new SecureRandom());
cipher = Cipher.getInstance("DES/CBC/NoPadding");
try {
cipher.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_3DES, new SecureRandom());
fail();
} catch (InvalidKeyException expected) {
}
}
use of javax.crypto.Cipher in project robovm by robovm.
the class CipherTest method test_doFinal$BI.
public void test_doFinal$BI() 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);
c.update(b, 0, 10);
try {
c.doFinal(b1, 5);
fail();
} catch (IllegalBlockSizeException expected) {
}
c = Cipher.getInstance("DES/CBC/NoPadding");
try {
c.doFinal(b1, 5);
fail();
} catch (IllegalStateException expected) {
}
c = Cipher.getInstance("DES/CBC/NoPadding");
c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_DES, ap);
c.update(b, 3, 8);
int len = c.doFinal(b1, 0);
assertEquals(0, len);
c = Cipher.getInstance("DES/CBC/PKCS5Padding");
c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_DES, ap);
c.update(b1, 0, 24);
try {
c.doFinal(b, 0);
fail();
} catch (BadPaddingException expected) {
}
b1 = new byte[6];
c = Cipher.getInstance("DESede");
c.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_3DES);
c.update(b, 3, 6);
try {
c.doFinal(b1, 5);
fail();
} catch (ShortBufferException expected) {
}
}
use of javax.crypto.Cipher in project robovm by robovm.
the class CipherTest method test_getAlgorithm.
/**
* javax.crypto.Cipher#getAlgorithm()
*/
public void test_getAlgorithm() throws Exception {
final String algorithm = "DESede/CBC/PKCS5Padding";
Cipher cipher = Cipher.getInstance(algorithm);
assertTrue("Cipher algorithm does not match", cipher.getAlgorithm().equals(algorithm));
}
use of javax.crypto.Cipher in project robovm by robovm.
the class CipherTest method test_doFinal$BII$B.
public void test_doFinal$BII$B() 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);
fail();
} catch (IllegalBlockSizeException expected) {
}
c = Cipher.getInstance("DES/CBC/NoPadding");
try {
c.doFinal(b, 0, 10, b1);
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);
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]);
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);
fail();
} catch (ShortBufferException expected) {
}
}
use of javax.crypto.Cipher in project robovm by robovm.
the class CipherTest method testGetParameters.
public void testGetParameters() throws Exception {
Cipher c = Cipher.getInstance("DES");
assertNull(c.getParameters());
}
Aggregations