0% found this document useful (0 votes)
3 views

Creating Digital Signature

The document is a Java program that creates a digital signature using the DSA algorithm. It prompts the user to enter some text, generates a key pair, and signs the message with the private key. Finally, it outputs the digital signature for the given text.

Uploaded by

balachatgpt3.0
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Creating Digital Signature

The document is a Java program that creates a digital signature using the DSA algorithm. It prompts the user to enter some text, generates a key pair, and signs the message with the private key. Finally, it outputs the digital signature for the given text.

Uploaded by

balachatgpt3.0
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.security.

KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.Signature;
import java.util.Scanner;
public class CreatingDigitalSignature {
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.println("Enter some text");
String msg = sc.nextLine();
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("DSA");
keyPairGen.initialize(2048);
KeyPair pair = keyPairGen.generateKeyPair();
PrivateKey privKey = pair.getPrivate();
Signature sign =
Signature.getInstance("SHA256withDSA");sign.initSign(privKey);
byte[] bytes = "msg".getBytes();
sign.update(bytes);
byte[] signature = sign.sign();
System.out.println("Digital signature for given text: "+new String(signature,
"UTF8"));

}
}

You might also like