The following sample code generates RSA public and private keys and save them in separate files. You can pass the file names as input parameters and the program generates keys with 1024-bit size. Before you can run the program you need to install the following jars in your classpath. Learn RSA Encryption and Decryption Basics