use of java.security.spec.AlgorithmParameterSpec in project platform_frameworks_base by android.
the class AndroidKeyPairGeneratorTest method testKeyPairGenerator_GenerateKeyPair_RSA_WithParams_Unencrypted_Success.
public void testKeyPairGenerator_GenerateKeyPair_RSA_WithParams_Unencrypted_Success() throws Exception {
AlgorithmParameterSpec spec = new RSAKeyGenParameterSpec(1024, BigInteger.valueOf(3L));
mGenerator.initialize(new KeyPairGeneratorSpec.Builder(getContext()).setAlias(TEST_ALIAS_1).setKeySize(1024).setAlgorithmParameterSpec(spec).setSubject(TEST_DN_1).setSerialNumber(TEST_SERIAL_1).setStartDate(NOW).setEndDate(NOW_PLUS_10_YEARS).build());
final KeyPair pair = mGenerator.generateKeyPair();
assertNotNull("The KeyPair returned should not be null", pair);
assertKeyPairCorrect(pair, TEST_ALIAS_1, "RSA", 1024, spec, TEST_DN_1, TEST_SERIAL_1, NOW, NOW_PLUS_10_YEARS);
}
use of java.security.spec.AlgorithmParameterSpec in project robovm by robovm.
the class CipherTest method testAES_ECB_NoPadding_IvParameters_Failure.
private void testAES_ECB_NoPadding_IvParameters_Failure(String provider) throws Exception {
SecretKey key = new SecretKeySpec(AES_128_KEY, "AES");
Cipher c = Cipher.getInstance("AES/ECB/NoPadding", provider);
AlgorithmParameterSpec spec = new IvParameterSpec(AES_IV_ZEROES);
try {
c.init(Cipher.ENCRYPT_MODE, key, spec);
fail("Should not accept an IV in ECB mode");
} catch (InvalidAlgorithmParameterException expected) {
}
}
use of java.security.spec.AlgorithmParameterSpec in project robovm by robovm.
the class CipherTest method test_initWithKeyAlgorithmParametersSecureRandom.
public void test_initWithKeyAlgorithmParametersSecureRandom() throws Exception {
AlgorithmParameterSpec ap = new IvParameterSpec(IV);
Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding");
c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_DES, ap, new SecureRandom());
assertNotNull(c.getParameters());
try {
c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_3DES, ap, new SecureRandom());
fail();
} catch (InvalidKeyException expected) {
}
try {
c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_DES, (AlgorithmParameters) null, new SecureRandom());
fail();
} catch (InvalidAlgorithmParameterException expected) {
}
c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_DES, ap, (SecureRandom) null);
assertNotNull(c.getParameters());
}
use of java.security.spec.AlgorithmParameterSpec in project robovm by robovm.
the class KeyAgreementTest method testInit01.
/**
* Test for the methods <code>init(Key key)</code>
* <code>init(Key key, SecureRandom random)</code>
* <code>init(Key key, AlgorithmParameterSpec params)</code>
* <code>init(Key key, AlgorithmParameterSpec params, SecureRandom random)</code>
* Assertion: throws InvalidKeyException when key is inappropriate
*/
public void testInit01() throws Exception {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
createKeys();
KeyAgreement[] kAgs = createKAs();
SecureRandom random = null;
AlgorithmParameterSpec aps = null;
DHParameterSpec dhPs = new DHParameterSpec(new BigInteger("56"), new BigInteger("56"));
for (int i = 0; i < kAgs.length; i++) {
try {
kAgs[i].init(publKey);
fail("InvalidKeyException must be throw");
} catch (InvalidKeyException e) {
}
try {
kAgs[i].init(publKey, new SecureRandom());
fail("InvalidKeyException must be throw");
} catch (InvalidKeyException e) {
}
try {
kAgs[i].init(publKey, random);
fail("InvalidKeyException must be throw");
} catch (InvalidKeyException e) {
}
try {
kAgs[i].init(publKey, dhPs);
fail("InvalidKeyException must be throw");
} catch (InvalidKeyException e) {
}
try {
kAgs[i].init(publKey, aps);
fail("InvalidKeyException must be throw");
} catch (InvalidKeyException e) {
}
try {
kAgs[i].init(publKey, dhPs, new SecureRandom());
fail("InvalidKeyException must be throw");
} catch (InvalidKeyException e) {
}
}
}
use of java.security.spec.AlgorithmParameterSpec in project robovm by robovm.
the class SignatureTest method testSetParameterAlgorithmParameterSpec.
/*
* Class under test for void setParameter(AlgorithmParameterSpec)
*/
public void testSetParameterAlgorithmParameterSpec() throws InvalidAlgorithmParameterException {
MySignature1 s = new MySignature1("ABC");
try {
s.setParameter((java.security.spec.AlgorithmParameterSpec) null);
fail("No expected UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
}
try {
Signature sig = getTestSignature();
sig.setParameter(new AlgorithmParameterSpec() {
});
} catch (InvalidAlgorithmParameterException e) {
fail("unexpected: " + e);
} catch (NoSuchAlgorithmException e) {
fail("unexpected: " + e);
}
}
Aggregations