Let's see how we can encrypt and decrypt information in Java using Public and Private Key. This tutorial is done in Java 8 so you may not find Base64 encoding API's in older version of Java. You can replace them with apache commons library. To generate public and private key follow the tutorial here.
FileInputStream privateKeyFile = new FileInputStream(
"E:/temp/lalit_private_keystore");