Java examples for Security:RSA
gen RSA Key Pair
//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); } } }