Skip to content

Instantly share code, notes, and snippets.

@samngms
Created August 6, 2018 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samngms/831675e1e1aa29c8f87c78bfa2082749 to your computer and use it in GitHub Desktop.
Save samngms/831675e1e1aa29c8f87c78bfa2082749 to your computer and use it in GitHub Desktop.
KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA");
kpGen.initialize(2048);
KeyPair keyPair = kpGen.generateKeyPair();
Random random = new SecureRandom();
byte[] data = new byte[256];
random.nextBytes(data);
Cipher cipher = Cipher.getInstance(__RSA_ENCRYPTION__);
cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPublic());
byte[] cipherText = cipher.doFinal(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment