Question

The Toronto-Dominion Bank
CA
Last activity: 22 Sep 2020 13:08 EDT
Need to write the Java code to read the text file and convert to SHA256Hash
I need to write the Java Code to read the text file and convert to SHA256Hash.
I am able to get the SHA256Hash for a string using the below code ( defined input & returnValule as local variables in the activity). I need to extend this Java code to read the contents from the text file and create SHA256Hash value.
Can anyone who has experience help with this ?
try {
java.security.MessageDigest digest = java.security.MessageDigest.getInstance("SHA-256");
try {
byte[] hash = digest.digest(input.getBytes("UTF-8"));
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < hash.length; i++) {
String hex = Integer.toHexString(0xff & hash[i]);
if (hex.length() == 1 && hexString.length() > 0) hexString.append('0');
hexString.append(hex);
}
returnValue = hexString.toString();
} catch (java.io.UnsupportedEncodingException e) {
oLog.debug("Unsupported Encoding Exception occured");
}
} catch (java.security.NoSuchAlgorithmException e) {
oLog.debug("No Such Algorithm exception occured");
}
***Edited by Moderator Kayla to update Content Type from Discussion to Question***