I have a simple hashing function in Java that I rewrote in Node.js but they produce different result.
Here is the Java:
public static String get_SHA_512_SecurePassword(String str, String customerId) {
    try {
        MessageDigest instance = MessageDigest.getInstance("SHA-512");
        instance.update(customerId.getBytes(StandardCharsets.UTF_8));
        byte[] digest = instance.digest(str.getBytes(StandardCharsets.UTF_8));
        StringBuilder sb = new StringBuilder();
        for (byte b : digest) {
            sb.append(Integer.toString((b & 255) + 256, 16).substring(1));
        }
        return sb.toString();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return null;
    }
}
and here is the Node.js equivalent I produced.
let crypto = require('crypto');
function get_SHA_512_SecurePassword(str, customerId) {
    let hash = crypto.createHash('sha512')
    hash.update(customerId, 'utf8')
    let value = hash.digest(str, 'uft8')
    console.log(value.toString('hex'))
    return value.toString('hex');
}
Can anyone explain what I am doing wrong or why they are different if I reproduced right?
 
     
     
    