Example usage for java.security.spec RSAKeyGenParameterSpec F4

List of usage examples for java.security.spec RSAKeyGenParameterSpec F4

Introduction

In this page you can find the example usage for java.security.spec RSAKeyGenParameterSpec F4.

Prototype

BigInteger F4

To view the source code for java.security.spec RSAKeyGenParameterSpec F4.

Click Source Link

Document

The public exponent-value F4 = 65537.

Usage

From source file:net.link.util.test.pkix.PkiTestUtils.java

public static KeyPair generateKeyPair(String algorithm)
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {

    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(algorithm);
    SecureRandom random = new SecureRandom();
    if ("RSA".equals(keyPairGenerator.getAlgorithm()))
        keyPairGenerator.initialize(new RSAKeyGenParameterSpec(RSA_KEYSIZE, RSAKeyGenParameterSpec.F4), random);
    else if (keyPairGenerator instanceof DSAKeyPairGenerator) {
        DSAKeyPairGenerator dsaKeyPairGenerator = (DSAKeyPairGenerator) keyPairGenerator;
        dsaKeyPairGenerator.initialize(DSA_MODLEN, false, random);
    }//from  ww  w  . j  av  a2  s .c o m
    return keyPairGenerator.generateKeyPair();
}

From source file:ru.jts_dev.authserver.config.KeyGenerationConfig.java

@Bean
public KeyPairGenerator RSAKeyPairGenerator()
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    KeyPairGenerator keygen;//from  w w  w.jav  a 2  s. c  om

    keygen = KeyPairGenerator.getInstance("RSA");
    RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
    keygen.initialize(spec);

    return keygen;
}

From source file:org.infoscoop.util.RSAKeyManager.java

public RSAKeyManager(BigInteger modulus, BigInteger exponent)
        throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException {

    if (log.isInfoEnabled())
        log.info("### Using RSAProvider is " + keyFactory.getProvider().getClass());

    RSAPrivateKeySpec privateKeySpec = new RSAPrivateKeySpec(modulus, exponent);
    privateKey = (RSAPrivateKey) keyFactory.generatePrivate(privateKeySpec);

    RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(modulus, RSAKeyGenParameterSpec.F4);
    publicKey = (RSAPublicKey) keyFactory.generatePublic(publicKeySpec);

}

From source file:org.demosoft.medieval.life.loginserver.LoginController.java

private LoginController() throws GeneralSecurityException {
    _log.info("Loading LoginContoller...");

    _keyPairs = new ScrambledKeyPair[10];

    KeyPairGenerator keygen = null;

    keygen = KeyPairGenerator.getInstance("RSA");
    RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
    keygen.initialize(spec);/*from   w ww. j a  v a 2s . co  m*/

    // generate the initial set of keys
    for (int i = 0; i < 10; i++) {
        _keyPairs[i] = new ScrambledKeyPair(keygen.generateKeyPair());
    }
    _log.info("Cached 10 KeyPairs for RSA communication");

    testCipher((RSAPrivateKey) _keyPairs[0]._pair.getPrivate());

    // Store keys for blowfish communication
    generateBlowFishKeys();
}

From source file:be.e_contract.mycarenet.common.SessionKey.java

/**
 * Generator constructor. Creates a new MyCareNet session key.
 * //w w  w  .j  a v  a  2 s  .  c o  m
 * @param keySize
 *            the RSA key size.
 */
public SessionKey(int keySize) {
    KeyPairGenerator keyPairGenerator;
    try {
        keyPairGenerator = KeyPairGenerator.getInstance("RSA");
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("RSA algo not available", e);
    }
    SecureRandom random = new SecureRandom();
    try {
        keyPairGenerator.initialize(new RSAKeyGenParameterSpec(keySize, RSAKeyGenParameterSpec.F4), random);
    } catch (InvalidAlgorithmParameterException e) {
        throw new RuntimeException("unsupported key size: " + keySize);
    }
    this.keyPair = keyPairGenerator.generateKeyPair();
}

From source file:com.l2jfree.loginserver.manager.GameServerManager.java

/**
 * Load RSA keys//w ww  . jav  a 2s.  c o m
 * @throws NoSuchAlgorithmException
 * @throws InvalidAlgorithmParameterException
 */
private void loadRSAKeys() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
    RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(512, RSAKeyGenParameterSpec.F4);
    keyGen.initialize(spec);

    _keyPairs = new KeyPair[KEYS_SIZE];
    for (int i = 0; i < KEYS_SIZE; i++) {
        _keyPairs[i] = keyGen.genKeyPair();
    }
    _log.info("GameServerManager: Cached " + _keyPairs.length + " RSA keys for Game Server communication.");
}

From source file:test.integ.be.fedict.trust.util.TestUtils.java

public static KeyPair generateKeyPair(String algorithm)
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {

    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(algorithm);
    SecureRandom random = new SecureRandom();
    if ("RSA".equals(keyPairGenerator.getAlgorithm())) {
        keyPairGenerator.initialize(new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4), random);
    } else if (keyPairGenerator instanceof DSAKeyPairGenerator) {
        DSAKeyPairGenerator dsaKeyPairGenerator = (DSAKeyPairGenerator) keyPairGenerator;
        dsaKeyPairGenerator.initialize(512, false, random);
    }//w w w .jav  a 2s. c  o m
    return keyPairGenerator.generateKeyPair();
}

From source file:org.cogroo.addon.util.SecurityUtil.java

public KeyPair genKeyPair() {
    KeyPair kpr = null;/*from   w w  w  . j a  v  a  2  s . co  m*/
    try {
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
        kpg.initialize(new RSAKeyGenParameterSpec(RSAKEYSIZE, RSAKeyGenParameterSpec.F4));
        kpr = kpg.generateKeyPair();
    } catch (NoSuchAlgorithmException e) {
        LOG.log(Level.SEVERE, "Error generating key pair", e);
    } catch (InvalidAlgorithmParameterException e) {
        LOG.log(Level.SEVERE, "Error generating key pair", e);
    }
    return kpr;
}

From source file:com.l2jfree.loginserver.manager.LoginManager.java

/**
 * Private constructor to avoid direct instantiation.
 * Initialize a key generator.// ww w .  j av a 2  s .  c om
 */
private LoginManager() {
    try {
        _log.info("LoginManager: initializing.");

        _hackProtection = new FastMap<InetAddress, FailedLoginAttempt>();

        _keyPairs = new ScrambledKeyPair[10];

        _service = (AccountsServices) L2Registry.getBean("AccountsServices");

        _connections = new FastList<L2Client>();

        KeyPairGenerator keygen = null;

        try {
            keygen = KeyPairGenerator.getInstance("RSA");
            RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
            keygen.initialize(spec);
        } catch (GeneralSecurityException e) {
            _log.fatal("Error in RSA setup:", e);
            _log.info("Server shutting down now");
            System.exit(1);
            return;
        }

        //generate the initial set of keys
        for (int i = 0; i < 10; i++) {
            _keyPairs[i] = new ScrambledKeyPair(keygen.generateKeyPair());
        }
        _log.info("LoginManager: Cached 10 KeyPairs for RSA communication");

        testCipher((RSAPrivateKey) _keyPairs[0].getPair().getPrivate());

        // Store keys for blowfish communication
        generateBlowFishKeys();
    } catch (GeneralSecurityException e) {
        _log.fatal("FATAL: Failed initializing LoginManager. Reason: " + e.getMessage(), e);
        System.exit(1);
    }

}

From source file:test.unit.org.owasp.webscarab.util.SunCertificateUtilsTest.java

private KeyPair generateKeyPair(int size) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
    SecureRandom random = new SecureRandom();
    keyPairGenerator.initialize(new RSAKeyGenParameterSpec(size, RSAKeyGenParameterSpec.F4), random);
    KeyPair keyPair = keyPairGenerator.generateKeyPair();
    return keyPair;
}