Hashing with SHA-256 in Javascript

importPackage(java.io);
importPackage(Packages.java.lang);
importClass(java.security.MessageDigest);
importClass(java.nio.charset.StandardCharsets);
importClass(java.lang.StringBuffer);

var varMyString = “JIMBO”;

var varDigest = MessageDigest.getInstance(“SHA-256”);

var varOriginalString = new java.lang.String(varMyString);
var varHashedString = varDigest.digest(varOriginalString.getBytes(StandardCharsets.UTF_8));

var varFinalString = new StringBuffer();
for (i = 0; i < varHashedString.length; i++)
{
varFinalString.append(Integer.toString((varHashedString[i] & 0xff) + 0x100, 16).substring(1));
}

print (“hash: ” + varFinalString);