How to encode the value in postman using SHA256 encryption

I have a below method in java which using the SHA256 algo to encrypt the string value 1234

public static String getHashedCode() {
    try {
        MessageDigest digest = MessageDigest.getInstance("SHA-256");
        String lastFourDigs = "1234";
        byte[] encodedHash = digest.digest(lastFourDigs.getBytes(StandardCharsets.UTF_8));
        return Base64.getEncoder().encodeToString(encodedHash);
    } catch (Exception e) {
        System.out.println("Exception: " + e);

    return null;

which will print hascode of 1234 as A6xnQhbz4Vx2HuGl4lXwZ5U2I8iziLRFnhP5eNfIRvQ

Now I want to achieve same thing in postman and tried below snippet

var sha256Hash =  CryptoJS.SHA256('1234').toString();
var base64Hash = CryptoJS.enc.Utf8.parse('sha256Hash');
var base64 = CryptoJS.enc.Base64.stringify(base64Hash);
pm.environment.set("encrypted", base64);

And its generating a different hashcode c2hhMjU2SGFzaA== which is not same as what java created.

Am i doing anything wrong here? Any help highly appreciated.!

This is an working example from when I was playing around with encryption keys.

Slightly different to your situation, but might put you on the right track.

// Encrypt
var secret = CryptoJS.AES.encrypt('My Message or Password', 'My Secret Key').toString();
console.log("secret = " + secret);

// Decrypt
var bytes  = CryptoJS.AES.decrypt(secret, 'My Secret Key');
console.log("bytes =" + bytes);

var originalText = bytes.toString(CryptoJS.enc.Utf8);

console.log("original text = " + originalText); // 'My Message or Password'