Search in sources :

Example 1 with RSAKeyGenParameterSpec

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.");
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) RSAKeyGenParameterSpec(java.security.spec.RSAKeyGenParameterSpec) KeyPairGenerator(java.security.KeyPairGenerator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 2 with RSAKeyGenParameterSpec

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);
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) RSAKeyGenParameterSpec(java.security.spec.RSAKeyGenParameterSpec) RSAKeyGenerationParameters(org.bouncycastle.crypto.params.RSAKeyGenerationParameters)

Example 3 with RSAKeyGenParameterSpec

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) {
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) RSAKeyGenParameterSpec(java.security.spec.RSAKeyGenParameterSpec) BigInteger(java.math.BigInteger) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) MyCipher(org.apache.harmony.crypto.tests.support.MyCipher) InvalidKeyException(java.security.InvalidKeyException) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Example 4 with RSAKeyGenParameterSpec

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());
}
Also used : RSAKeyGenParameterSpec(java.security.spec.RSAKeyGenParameterSpec)

Example 5 with RSAKeyGenParameterSpec

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());
}
Also used : RSAKeyGenParameterSpec(java.security.spec.RSAKeyGenParameterSpec)

Aggregations

RSAKeyGenParameterSpec (java.security.spec.RSAKeyGenParameterSpec)44 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)19 BigInteger (java.math.BigInteger)18 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)14 KeyPair (java.security.KeyPair)10 KeyPairGenerator (java.security.KeyPairGenerator)8 RSAPublicKey (java.security.interfaces.RSAPublicKey)8 ECPublicKey (java.security.interfaces.ECPublicKey)7 PublicKey (java.security.PublicKey)6 KeyPairGeneratorSpec (android.security.KeyPairGeneratorSpec)5 ExportResult (android.security.keymaster.ExportResult)5 ASN1Integer (com.android.org.bouncycastle.asn1.ASN1Integer)5 DERBitString (com.android.org.bouncycastle.asn1.DERBitString)5 DERInteger (com.android.org.bouncycastle.asn1.DERInteger)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InvalidKeyException (java.security.InvalidKeyException)5 PrivateKey (java.security.PrivateKey)5 ProviderException (java.security.ProviderException)5 Certificate (java.security.cert.Certificate)5 CertificateFactory (java.security.cert.CertificateFactory)5