Skip to content

Uncaught __dir__ while trying to generate a SubtleCrypto.generateKey() #2462

Discussion options

You must be logged in to vote

I confirm, the error was happening because SubtleCrypto is only available in HTTPS...

Anyway, making some test with the method of SubtleCrypto
it make me almost puke... They have made it complex for no reason ! (when I compare the same function in 🐍 Python, damn it so much easier, readable, make sense !)

//The minimum to generate a hash and print it !!! 🤮 
const sha256 = async (data) => {
    const textAsBuffer = new TextEncoder().encode(data);
    const hashBuffer = await window.crypto.subtle.digest('SHA-256', textAsBuffer);
    const hashArray = Array.from(new Uint8Array(hashBuffer))
    const digest = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
    return digest;
}
const

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@BobSquarePants
Comment options

Answer selected by BobSquarePants
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant