0% found this document useful (0 votes)
8 views2 pages

RSA Digital Signature Implementation

This Java program implements a Digital Signature scheme using RSA. It prompts the user to input two prime numbers, generates public and private keys, and allows for the creation and verification of a digital signature for a given message. The program checks the validity of the signature against the received message and outputs the result of the verification process.

Uploaded by

srushtishinde341
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

RSA Digital Signature Implementation

This Java program implements a Digital Signature scheme using RSA. It prompts the user to input two prime numbers, generates public and private keys, and allows for the creation and verification of a digital signature for a given message. The program checks the validity of the signature against the received message and outputs the result of the verification process.

Uploaded by

srushtishinde341
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

AIM:- WAP to implement Digital Signature scheme using RSA.

import [Link];
import [Link];
import [Link];

public class RSADigitalSignatureWithPrimes {

static BigInteger modExp(BigInteger base, BigInteger exp, BigInteger mod) {


return [Link](exp, mod);
}

static boolean isPrime(BigInteger n) {


return [Link](20);
}

public static void main(String[] args) {


Scanner sc = new Scanner([Link]);
SecureRandom rand = new SecureRandom();

[Link]("Enter prime number p: ");


BigInteger p = [Link]();
if (!isPrime(p)) {
[Link]("p is not prime. Exiting...");
return;
}

[Link]("Enter prime number q: ");


BigInteger q = [Link]();
if (!isPrime(q)) {
[Link]("q is not prime. Exiting...");
return;
}

BigInteger n = [Link](q);
BigInteger phi = ([Link]([Link])).multiply([Link]([Link]));

// Dynamically choose e and compute d


BigInteger e, d;
while (true) {
e = new BigInteger([Link](), rand);
if ([Link]([Link]) > 0 && [Link](phi) < 0 &&
[Link](e).equals([Link])) {
d = [Link](phi);
if (![Link](d)) {
break; // valid e found
}
}
}

[Link]("\nKeys Generated Successfully!");


[Link]("Public Key (e, n): (" + e + ", " + n + ")");
[Link]("Private Key (d, n): (" + d + ", " + n + ")");

[Link]("\nEnter original message (number): ");


BigInteger message = [Link]();

BigInteger signature = modExp(message, d, n);


[Link]("Generated Digital Signature: " + signature);

[Link]("\nEnter received message (number): ");


BigInteger receivedMessage = [Link]();

[Link]("Enter received signature: ");


BigInteger receivedSignature = [Link]();

BigInteger verified = modExp(receivedSignature, e, n);


[Link]("Decrypted Signature Value: " + verified);

if ([Link](receivedMessage)) {
[Link]("Signature Verified Successfully!");
} else {
[Link]("Signature Verification Failed!");
}

[Link]();
}
}

You might also like