js-sha256 icon indicating copy to clipboard operation
js-sha256 copied to clipboard

How to pass the input configs Input Encoding, Output Encoding( UTF-8, HMAC )

Open thangpqgm opened this issue 1 year ago • 1 comments

Hi, I see in your online demo tool, you can adjust Input/Output encoding and hmac Encoding, How can I do it with the hmac function in the code

import {sha256} from 'js-sha256';
console.log(sha256.hmac('key', 'value')) // <= I need to set encoding

image

Thank you!

thangpqgm avatar Sep 05 '24 05:09 thangpqgm

This library can accept binary such as bytes array or Uint8Array. See example. You can convert your data to bytes before input. This library can also output bytes and you can convert to other encodings. I use other libraries handle encoding outside this library. For example, I use hi-base64 to handle base64 encoding. You can do something like:

base64.encode(sha256.digest(''))

emn178 avatar Sep 06 '24 00:09 emn178