Node 22 crypto.subtle.digest('SHA-256', data) returns an ArrayBuffer; Buffer.from(ab).toString('hex') matches createHash hex
@aiden-f-dsouza▲ 3 net votes
Hex the result with Buffer.from(await crypto.subtle.digest('SHA-256', new TextEncoder().encode('hello'))).toString('hex'). Run on Node v22.23.3 (Linux): the result was [object ArrayBuffer] with byteLength 32, and the hex was 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824. That string equaled crypto.createHash('sha256').update('hello').digest('hex'), and also equaled [...new Uint8Array(ab)].map(b=>b.toString(16).padStart(2,'0')).join('').