IMPLEMENTATION OF SHA-1 ALGORITHM using JAVA

Image
AIM: To   write a java program to calculate the message digest of a text using the SHA-1 algorithm ALGORITHM: Step 1: Input the plain text Step 2: Append padding bits Step 3: Append length Step 4:Initialize   buffer. Step 5: Process message in 512-bit (16word)blocks Step 6: Encrypted in hexa decimal format Step 7: Display the encrypted text. PROGRAM: importjava.security.*; public class SHA1 { public static void main(String[] a) { try { MessageDigest md = MessageDigest.getInstance("SHA1"); System.out.println("Message digest object info: "); System.out.println(" Algorithm = " +md.getAlgorithm()); System.out.println(" Provider = " +md.getProvider()); System.out.println(" ToString = " +md.toString());   String input = ""; md.update(input.getBytes()); byte[] output = md.digest(); System.out.println(); System.out.println("SHA1(\""+...

IMPLEMENTATION OF MD5 ALGORITHM using Java


AIM:

To write a program in java to  calculate the message digest of a text using the MD-5.



ALGORITHM:

Step1: Append padding bits to the input plain text

Step2: Append length

Step3: Initialize MD buffer

Step4: Process message in 512-bit(16word)blocks

Step5: Display the hashed text.



PROGRAM:

import java.io.FileInputStream;

import java.io.UnsupportedEncodingException;

importjava.math.BigInteger;

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;

public class MD5 {

    public static String getMD5(String input) {

        try {

MessageDigest md = MessageDigest.getInstance("MD5");

byte[] messageDigest = md.digest(input.getBytes());

BigInteger number = new BigInteger(1, messageDigest);

            String hashtext = number.toString(16);

            // Now we need to zero pad it if you actually want the full 32 chars.

while (hashtext.length() < 32) {

hashtext = "0" + hashtext;

            }

            return hashtext;

        }

        catch (NoSuchAlgorithmException e) {

            throw new RuntimeException(e);

        }

    }

public static void main(String[] args) throws NoSuchAlgorithmException {

System.out.println(getMD5("hai"));

    }

}



OUTPUT:

Comments

Popular posts from this blog

IMPLEMENTATION OF SHA-1 ALGORITHM using JAVA

IMPLEMENTATION OF RSA ALGORITHM using c++

IMPLEMENTATION OF DIFFIE HELLMAN KEY EXCHANGE ALGORITHM