0% found this document useful (0 votes)
7 views3 pages

WMS 2.1 20BCS5674

Uploaded by

Nishtha Sharma
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)
7 views3 pages

WMS 2.1 20BCS5674

Uploaded by

Nishtha Sharma
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
You are on page 1/ 3

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 2.1
Student Name: Nishtha Sharma UID: 20BCS5674
Branch: BE-CSE Section/Group: 20BCS_WM_609 B
Semester: 5th Subject Name: Web and Mobile Security
Lab

Aim:
Write a program to generate message digest for the given message using
the SHA/MD5 algorithm and verify the integrity of message.

Objective:
Encrypt the plaintext string from user using SHA Algorithm.

Hardware/Software Requirements:
Windows 7 and Above.

Tools used:
1. Eclipse IDE
2. JDK (Java Development kit)
3. IntelliJ IDEA

Script/Code/Steps:
import java.util.Scanner; import
java.math.BigInteger; import
java.security.MessageDigest;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

import java.security.NoSuchAlgorithmException;

public class Main {


public static String encryptString(String input, String
method) {
try {
MessageDigest md = MessageDigest.getInstance(method);
byte[] messageDigest = md.digest(input.getBytes());
BigInteger no = new BigInteger(1, messageDigest);
String hashtext = no.toString(16);
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
return hashtext;
}
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}

public static void main(String args[]) throws


NoSuchAlgorithmException {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the String: ");
String str = sc.nextLine();
System.out.println("SHA Encrypted String: " +
encryptString(str, "SHA-1"));
System.out.println("MD5 Encrypted String: " +
encryptString(str, "MD5"));
}
}

Output Screenshots:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Learning Outcomes:
1. Learnt about the encryption techniques.
2. Learnt about hashing and its implementation.
3. Learnt how to implement hash function in Java.
4. Learnt how to implement MD5 Algorithm.
5. Learnt how to implement SHA Algorithm.

You might also like