use of java.security.SecureRandom in project robovm by robovm.
the class KeyAgreementTest method test_initLjava_security_KeyLjava_security_SecureRandom.
public void test_initLjava_security_KeyLjava_security_SecureRandom() throws Exception {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
createKeys();
KeyAgreement[] kAgs = createKAs();
KeyAgreement ka = KeyAgreement.getInstance("DH");
ka.init(privKey, new SecureRandom());
try {
ka.init(publKey, new SecureRandom());
fail("InvalidKeyException expected");
} catch (InvalidKeyException e) {
//expected
}
}
use of java.security.SecureRandom in project robovm by robovm.
the class APSpecSpi method testKeyGeneratorSpi01.
/**
* Test for <code>KeyGeneratorSpi</code> constructor Assertion: constructs
* KeyGeneratorSpi
*/
public void testKeyGeneratorSpi01() throws InvalidAlgorithmParameterException {
Mock_KeyGeneratorSpi kgSpi = new Mock_KeyGeneratorSpi();
assertNull("Not null result", kgSpi.engineGenerateKey());
try {
kgSpi.engineInit(77, new SecureRandom());
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
try {
kgSpi.engineInit(new SecureRandom());
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
AlgorithmParameterSpec aps = null;
try {
kgSpi.engineInit(aps, new SecureRandom());
fail("InvalidAlgorithmParameterException must be thrown when parameter is null");
} catch (InvalidAlgorithmParameterException e) {
}
aps = new APSpecSpi();
kgSpi.engineInit(aps, new SecureRandom());
}
use of java.security.SecureRandom in project robovm by robovm.
the class myKeyGenerator method testInitParams.
/*
* Test for <code>init(AlgorithmParameterSpec params)</code> and
* <code>init(AlgorithmParameterSpec params, SecureRandom random)</code> methods
* Assertion: throws InvalidAlgorithmParameterException when params is null
*/
public void testInitParams() throws Exception {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
KeyGenerator[] kgs = createKGs();
AlgorithmParameterSpec aps = null;
for (int i = 0; i < kgs.length; i++) {
try {
kgs[i].init(aps);
fail("InvalidAlgorithmParameterException must be thrown");
} catch (InvalidAlgorithmParameterException e) {
}
try {
kgs[i].init(aps, new SecureRandom());
fail("InvalidAlgorithmParameterException must be thrown");
} catch (InvalidAlgorithmParameterException e) {
}
}
}
use of java.security.SecureRandom in project robovm by robovm.
the class CipherOutputStream1Test method test_ConstructorLjava_io_OutputStreamLjavax_crypto_Cipher.
public void test_ConstructorLjava_io_OutputStreamLjavax_crypto_Cipher() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
KeyGenerator kg = KeyGenerator.getInstance("DES");
kg.init(56, new SecureRandom());
Key key = kg.generateKey();
Cipher c = Cipher.getInstance("DES/CBC/NoPadding");
c.init(Cipher.ENCRYPT_MODE, key);
CipherOutputStream cos = new CipherOutputStream(baos, c);
assertNotNull(cos);
}
use of java.security.SecureRandom in project robovm by robovm.
the class CipherTest method test_getOutputSizeI.
/**
* javax.crypto.Cipher#getOutputSize(int)
*/
public void test_getOutputSizeI() throws Exception {
Cipher cipher = Cipher.getInstance(ALGORITHM_3DES + "/ECB/PKCS5Padding");
try {
cipher.getOutputSize(25);
fail();
} catch (IllegalStateException expected) {
}
cipher.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_3DES, new SecureRandom());
// A 25-byte input could result in at least 4 8-byte blocks
int result = cipher.getOutputSize(25);
assertTrue("Output size too small", result > 31);
// A 8-byte input should result in 2 8-byte blocks
result = cipher.getOutputSize(8);
assertTrue("Output size too small", result > 15);
}
Aggregations