Android examples for java.security:Key
generate Asymmetric Key Pair
//package com.java2s; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; public class Main { private static final String ASYMMETRIC_ALGORITHM = "RSA"; public static KeyPair generateAsymmetricKeyPair(int keySize) { KeyPairGenerator kgen;// w w w . ja va 2 s .c om try { kgen = KeyPairGenerator.getInstance(ASYMMETRIC_ALGORITHM); kgen.initialize(keySize); return kgen.generateKeyPair(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; } }