Skip to content

What is the best way to work with utf-8 encoded string #584

Answered by kjur
aaa006bd asked this question in Q&A
Discussion options

You must be logged in to vote

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:

$ openssl sha256 t1.json
SHA256(t1.json)= 6bbaebd8da1853f65298b72a970c3a44b9d4d2bdf3299330968441efe8fd7c72

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 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by aaa006bd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants