gen RSA Key Pair - Java Security

Java examples for Security:RSA

Description

gen RSA Key Pair

Demo Code


//package com.java2s;

import java.security.KeyPair;
import java.security.KeyPairGenerator;

public class Main {
    public static KeyPair genRSAKeyPair() {
        return genRSAKeyPair(2048);
    }/*from  w  ww  .  j a  v  a2s.c om*/

    public static KeyPair genRSAKeyPair(int keyLength) {
        try {
            KeyPairGenerator keyPairGenerator = KeyPairGenerator
                    .getInstance("RSA");
            keyPairGenerator.initialize(keyLength);
            return keyPairGenerator.generateKeyPair();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

Related Tutorials