oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.95k stars 2.75k forks source link

Need base64url support in digest #3642

Closed yolmcore closed 7 months ago

yolmcore commented 1 year ago

What is the problem this feature would solve?

Right now I can only return a TypedArray or base64 string but I need a base64url for my usage.

What is the feature you are proposing to solve the problem?

add another option to digest "base64url"

What alternatives have you considered?

I'm replacing base64 to base64url (replaceAll), but it is very inefficient.

Jarred-Sumner commented 1 year ago

Where is base64url not supported? In crypto.createHash()?

yolmcore commented 1 year ago

Maybe I misread the docs, but simple hasher in https://bun.sh/docs/api/hashing does not support SHA256 and the CryptoHasher digest method does not support base64url encoding and I don't see a base64url encoding method that takes a TypedArray.

paperdave commented 7 months ago

this seems to work now. not sure when it was fixed

// Node API
const crypto = require("crypto");
const hasher = crypto.createHash("sha256");
hasher.update("hello world");
console.log(hasher.digest("base64url"));

// Bun
const hasher2 = new Bun.CryptoHasher("sha256");
hasher2.update("hello world");
console.log(hasher2.digest("base64url"));

as compared to base64 where there is a + in place of the -