result as Uint8Array
psvz opened this issue · comments
var md = forge.md.sha256.create()
md.update(data)
const hash = md.digest()
This gives me some weird Object. How do I get 32 bytes in Uint8Array in the most performant way?
Okay, so, basically, to operate on bytes properly:
// msg is Uint8Array
var yuck = ''
msg.forEach(b => yuck += String.fromCharCode(b))
var md = forge.md.sha256.create()
md.update(yuck)
const hash = Uint8Array.from(md.digest().data, c => c.charCodeAt(0))
I am wondering if there is more standard way...
Kind of wish they removed all kind of NodeJS specific stuff and used web api's instead... meaning removing all node:buffer
and node:crypto
and instead used only Uint8Array
& "web crypto" (and also DataView to modify the data)
NodeJS have web crypto built right in now on the global scope, but requires v18+
earlier version (v15+) can use
import { webcrypto as crypto } from 'node:crypto'