Skip to content

Instantly share code, notes, and snippets.

@zaki50
Created February 17, 2011 12:30
Show Gist options
  • Save zaki50/831620 to your computer and use it in GitHub Desktop.
Save zaki50/831620 to your computer and use it in GitHub Desktop.
final KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(new RSAKeyGenParameterSpec(2048, RSAKeyGenParameterSpec.F4));
Log.i("hamatz", "generating RSA key pair...");
final long start = SystemClock.uptimeMillis();
final KeyPair kp = kpg.generateKeyPair();
final long end = SystemClock.uptimeMillis();
Log.i("hamatz", "done: " + (end-start) + "ms.");
final RSAPrivateKey privkey = (RSAPrivateKey) kp.getPrivate();
final RSAPublicKey pubkey = (RSAPublicKey) kp.getPublic();
final byte[] encodedPrivkey = privkey.getEncoded();
final byte[] encodedPubkey = pubkey.getEncoded();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment