K6 crypto sha256 digest question

in python

In [18]: data = '{"CIDR": "192.168.0.0/16", "clientToken": "79fa97e3-
    ...: c48b-xxxx-9f46-6a13d8163678", "enableIpv6": false, "name": "
    ...: vpc-for-test-wowop1", "regionID": "bb9fdb42056f11eda1610242a
    ...: c110002"}'

In [19]: hashlib.sha256(data.encode('utf-8')).hexdigest()
Out[19]: '4267a781e823207f868dfa448b1f0a775cebe40b97ba207aa5b82bcebdf906ab'

and in k6 crypto

const bodyStr = JSON.stringify({"CIDR": "192.168.0.0/16", "clientToken": "79fa97e3-c48b-xxxx-9f46-6a13d8163678", "enableIpv6": false, "name": "vpc-for-test-wowop1", "regionID": "bb9fdb42056f11eda1610242ac110002"});
    const hasher = crypto.createHash("sha256")
    hasher.update(bodyStr)
    const bodyDigest = hasher.digest("hex");
    console.log(bodyDigest);   // output d1eb42f56393693fa72ade6f8b65c1a533e345a3195529d2c8a8293745e61eb4

why they are different

Hi @fatelei, welcome the community forum!

You are not using the same input in both cases - in the one case you make JSON.stringify stringify the json which specificallyt strips all the spaces.

If you replace the input for the k6 version with the string from the python one it will work without problems.

thanks