Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

pls tracing output for this programs and comment how get output ------------------------------------------------------------------ Program1: package javaapplication4; /*package com.mkyong.test; import java.security.MessageDigest; /** * * @author Dr.Hossam Diab

pls tracing output for this programs and comment how get output

------------------------------------------------------------------

Program1:

package javaapplication4;

/*package com.mkyong.test;

import java.security.MessageDigest;

/**

*

* @author Dr.Hossam Diab

*/

import java.security.MessageDigest;

public class JavaApplication4 {

public static void main(String[] args)throws Exception

{

String password = "1234*5689";

MessageDigest md = MessageDigest.getInstance("SHA-256");

md.update(password.getBytes());

byte byteData[] = md.digest();

//convert the byte to hex format method 1

StringBuffer sb = new StringBuffer();

for (int i = 0; i

sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));

}

System.out.println("Hex format : " + sb.toString());

//convert the byte to hex format method 2

StringBuffer hexString = new StringBuffer();

for (int i=0;i

String hex=Integer.toHexString(0xff & byteData[i]);

if(hex.length()==1) hexString.append('0');

hexString.append(hex);

}

System.out.println("Hex format : " + hexString.toString());

}

}

image text in transcribed

Program2:

package javaapplication5;

import java.io.FileInputStream;

import java.security.MessageDigest;

/**

*

* @author Dr.Hossam Diab

*/

public class JavaApplication5 {

public static void main(String[] args)throws Exception

{

MessageDigest md = MessageDigest.getInstance("SHA-256");

FileInputStream fis = new FileInputStream("d:\\loging.txt");

byte[] dataBytes = new byte[1024];

int nread = 0;

while ((nread = fis.read(dataBytes)) != -1) {

md.update(dataBytes, 0, nread);

};

byte[] mdbytes = md.digest();

//convert the byte to hex format method 1

StringBuffer sb = new StringBuffer();

for (int i = 0; i

sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));

}

System.out.println("Hex format : " + sb.toString());

//convert the byte to hex format method 2

StringBuffer hexString = new StringBuffer();

for (int i=0;i

hexString.append(Integer.toHexString(0xFF & mdbytes[i]));

}

System.out.println("Hex format : " + hexString.toString());

}

}

image text in transcribed

Program3:

package javaapplication6;

import java.io.FileInputStream;

import java.security.MessageDigest;

/**

*

* @author Dr.Hossam Diab

*/

public class JavaApplication6 {

public static void main(String[] args)throws Exception

{

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

FileInputStream fis = new FileInputStream("d:\\loging.txt");

byte[] dataBytes = new byte[1024];

int nread = 0;

while ((nread = fis.read(dataBytes)) != -1) {

md.update(dataBytes, 0, nread);

};

byte[] mdbytes = md.digest();

//convert the byte to hex format method 1

StringBuffer sb = new StringBuffer();

for (int i = 0; i

sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));

}

System.out.println("Hex format : " + sb.toString());

//convert the byte to hex format method 2

StringBuffer hexString = new StringBuffer();

for (int i=0;i

hexString.append(Integer.toHexString(0xFF & mdbytes[i]));

}

System.out.println("Hex format : " + hexString.toString());

}

}

image text in transcribed

Output JavaApplication2 (run) Hex format : 0ff05 Hex format: Off05a903ebecae619bab5ac3Ofe53941680882e735332b21e5765565b26a65c BUILD SUCCESSFUL (total time: 0 seconds) a903ebecae619bab5ac30fe53941680882e73 5332b21e5765565b26a65c Output JavaApplication1 (run) Hex format 2cf24dba5fb0a30e26e83b2ac5b9e29e1bl6 Hex format 2cf24dba5fb0a3e26e83b2ac5b9e29elb16 BUILD SUCCESSFUL (total time: 0 seconds) 1e5c c1fa7425e73043362938b9824 1e5c1fa7425e7343362938b9824 Output JavaApplication1 (run) Hex format 5d41402abc4b2a76b9719d911017c592 Hex Eormat BUILD SUCCESSFUL (total time: 0 seconds) 5d41402abc4b2a76b9719d911017c592

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

4. Choose appropriate and powerful language

Answered: 1 week ago

Question

2. Choose an appropriate organizational pattern for your speech

Answered: 1 week ago