DIGITAL SIGNATURE ALGORITHM
EX. NO. : 3
AIM:
To implement the Digital Signature Algorithm (DSA) using Java for generating a digital
signature and verifying the authenticity and integrity of a given message.
ALGORITHM:
Step 1: Read the input message from the user.
Step 2: Generate a DSA public–private key pair using KeyPairGenerator.
Step 3: Initialize the Signature object with SHA256withDSA and the private key.
Step 4: Generate the digital signature for the input message.
Step 5: Display the generated digital signature in Base64 format.
Step 6: Initialize the Signature object with the public key for verification.
Step 7: Verify the digital signature using the original message.
Step 8: Display the verification result.
PROGRAM:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].Base64;
import [Link];
public class DigitalSignatureDSA {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner([Link]);
[Link]("Enter the message:");
String message = [Link]();
// 1. Key Pair Generation
KeyPairGenerator keyGen = [Link]("DSA");
[Link](2048);
KeyPair keyPair = [Link]();
PrivateKey privateKey = [Link]();
PublicKey publicKey = [Link]();
// 2. Create Digital Signature
Signature signature = [Link]("SHA256withDSA");
[Link](privateKey);
[Link]([Link]());
byte[] digitalSignature = [Link]();
[Link]("Digital Signature (Base64):");
[Link]([Link]().encodeToString(digitalSignature));
// 3. Verify Digital Signature
Signature verifySig = [Link]("SHA256withDSA");
[Link](publicKey);
[Link]([Link]());
boolean isVerified = [Link](digitalSignature);
[Link]("Signature Verification Result: " + isVerified);
}
}
OUTPUT:
RESULT:
The digital signature is successfully generated and verified using the Digital Signature
Algorithm (DSA).