Question
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()); } } 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()); } } 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()); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started