Just use the javax.crypto
and java.security
packages. It's in the Java standard platform.
KeyPair keys = KeyPairGenerator.getInstance("RSA").generateKeyPair();
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, keys.getPublic());
byte[] encrypted = cipher.doFinal(rawData);
Links for the official documentation:
- Package javax.crypto documentation
- Package java.security documentation