Question

43
Views
Close popover
Satya Kesani (SatyaKesani)
Tech Mahindra
PEGA Senior System Architect
Tech Mahindra
CA
SatyaKesani Member since 2016 2 posts
Tech Mahindra
Posted: September 22, 2020
Last activity: September 22, 2020

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***

Pega Platform 8.4 Case Management Financial Services Senior System Architect