Code example for RSAKeyGenParameterSpec

0
    public static KeyPair generateRsaKeyPair(int keySize,
                                             BigInteger publicExponent) {
        KeyPair keys = null;
        try { 
            KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
            RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(keySize,
                    publicExponent);
            keyGen.initialize(spec);
            keys = keyGen.generateKeyPair();
        } catch (Exception e) {
            if (DEBUG)
                e.printStackTrace();
        } 
        return keys;
    } 
 
    /** 
     * generates a RSA public key with given modulus and public exponent 
     * 
     * @param modulus        (must be positive? don't know exactly) 
     * @param publicExponent