-
Hi,
Here I need to use updateHex because the datastring might be constructed from a Json object as well. The way I am doing it is not working because the signature is not created properly (UTF-8 content must be signed in the correct UTF-8 encoding). Is there anything that I am missing? or What should be the way to do it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Jsrsasign works with UTF-8 non ascii characters. Here is a sample input JSON file "t1.json" contents (no new line in end of file): {
"text": "Zeyestraße"
} SHA256 hash value of this file will be:
Then here is hash calculation sample of jsrsasign with updateString method: const jsrsasign = require("jsrsasign");
const fs = require("fs");
const s = fs.readFileSync("t1.json", "utf8");
let md = new jsrsasign.KJUR.crypto.MessageDigest({alg: "sha256"});
md.updateString(s);
console.log(md.digest()); Here is another sample with updateHex method: const jsrsasign = require("jsrsasign");
const fs = require("fs");
const s = fs.readFileSync("t1.json", "utf8");
let md = new jsrsasign.KJUR.crypto.MessageDigest({alg: "sha256"});
md.updateHex(jsrsasign.utf8tohex(s));
console.log(md.digest()); Both script will show the same correct hash value:
I hope these help you. |
Beta Was this translation helpful? Give feedback.
Jsrsasign works with UTF-8 non ascii characters. Here is a sample input JSON file "t1.json" contents (no new line in end of file):
SHA256 hash value of this file will be:
Then here is hash calculation sample of jsrsasign with updateString method:
Here is another sample with updateHex method: