Generate RSA Keys Example

This program demonstrates generating RSA key pairs.

Problem Statement

Write a Java program that generates RSA public and private keys.

Source Code

1 import java.security.*;
2 public class RSAKeyGenExample {
3 public static void main(String[] args) {
4 System.out.println("Eduinq RSA KeyGen Example");
5 try {
6 KeyPairGenerator kpg=KeyPairGenerator.getInstance("RSA");
7 kpg.initialize(2048);
8 KeyPair kp=kpg.generateKeyPair();
9 System.out.println("Eduinq Public Key: "+kp.getPublic());
10 System.out.println("Eduinq Private Key: "+kp.getPrivate());
11 } catch(Exception e) {
12 System.out.println("Eduinq Exception: "+e.getMessage());
13 }
14 }
15 }

Program Output

					Eduinq RSA KeyGen Example
Eduinq Public Key: Sun RSA public key...
Eduinq Private Key: Sun RSA private key...
				

Explanation

RSA key generation uses KeyPairGenerator. - Produces public/private key pair. - Exception handling ensures safe operations. - In enterprise systems, RSA keys secure communication. Conclusion: Shows generating RSA keys.

Quick Links to Explore