use of java.security.spec.RSAKeyGenParameterSpec in project jdk8u_jdk by JetBrains.
the class SpecTest method main.
public static void main(String[] args) {
int failCount = 0;
// Test key size.
int size = Integer.parseInt(args[0]);
try {
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(KEYALG, PROVIDER);
kpg1.initialize(new RSAKeyGenParameterSpec(size, RSAKeyGenParameterSpec.F4));
if (!specTest(kpg1.generateKeyPair(), RSAKeyGenParameterSpec.F4)) {
failCount++;
}
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance(KEYALG, PROVIDER);
kpg2.initialize(new RSAKeyGenParameterSpec(size, RSAKeyGenParameterSpec.F0));
if (!specTest(kpg2.generateKeyPair(), RSAKeyGenParameterSpec.F0)) {
failCount++;
}
} catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidAlgorithmParameterException ex) {
ex.printStackTrace(System.err);
failCount++;
}
if (failCount != 0) {
throw new RuntimeException("There are " + failCount + " tests failed.");
}
}
use of java.security.spec.RSAKeyGenParameterSpec in project robovm by robovm.
the class KeyPairGeneratorSpi method initialize.
public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException {
if (!(params instanceof RSAKeyGenParameterSpec)) {
throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
}
RSAKeyGenParameterSpec rsaParams = (RSAKeyGenParameterSpec) params;
param = new RSAKeyGenerationParameters(rsaParams.getPublicExponent(), random, rsaParams.getKeysize(), defaultTests);
engine.init(param);
}
use of java.security.spec.RSAKeyGenParameterSpec in project robovm by robovm.
the class CipherTest method test_initWithAlgorithmParameterSpec.
/**
* javax.crypto.Cipher#init(int, java.security.Key,
* java.security.spec.AlgorithmParameterSpec)
*/
public void test_initWithAlgorithmParameterSpec() throws Exception {
AlgorithmParameterSpec ap = new IvParameterSpec(IV);
Cipher cipher = Cipher.getInstance(ALGORITHM_3DES + "/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_3DES, ap);
byte[] cipherIV = cipher.getIV();
assertTrue("IVs differ", Arrays.equals(cipherIV, IV));
cipher = Cipher.getInstance("DES/CBC/NoPadding");
try {
cipher.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_3DES, ap);
fail();
} catch (InvalidKeyException expected) {
}
cipher = Cipher.getInstance("DES/CBC/NoPadding");
ap = new RSAKeyGenParameterSpec(10, new BigInteger("10"));
try {
cipher.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_DES, ap);
fail();
} catch (InvalidAlgorithmParameterException expected) {
}
}
use of java.security.spec.RSAKeyGenParameterSpec in project robovm by robovm.
the class RSAKeyGenParameterSpecTest method testGetKeysize.
/**
* Test for <code>getKeySize()</code> method<br>
* Assertion: returns key size value
*/
public final void testGetKeysize() {
RSAKeyGenParameterSpec rkgps = new RSAKeyGenParameterSpec(512, BigInteger.valueOf(0L));
assertEquals(512, rkgps.getKeysize());
}
use of java.security.spec.RSAKeyGenParameterSpec in project robovm by robovm.
the class RSAKeyGenParameterSpecTest method testGetPublicExponent.
/**
* Test for <code>getPublicExponent()</code> method<br>
* Assertion: returns public exponent value
*/
public final void testGetPublicExponent() {
RSAKeyGenParameterSpec rkgps = new RSAKeyGenParameterSpec(512, BigInteger.valueOf(0L));
assertEquals(0, rkgps.getPublicExponent().intValue());
}
Aggregations