Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URIError: URI malformed #19

Open
alexgleason opened this issue Nov 4, 2022 · 1 comment
Open

URIError: URI malformed #19

alexgleason opened this issue Nov 4, 2022 · 1 comment

Comments

@alexgleason
Copy link

I'm using this library in a browser, to decode an hmac signature in base64.

// This line crashes:
const sig = decode("s11AVt9BuoYTNNOSS8oS9TzUeh0");

const bytes = new TextEncoder().encode(sig);

const verified = await crypto.subtle.verify(
  "HMAC",
  key,
  signature,
  bytes,
);

The result:

URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at decode2 (index.js:67:14)
    at decodeAndVerifyUrl (index.js:83:62)
    at Object.handleFetch [as fetch] (index.js:131:23) {
  stack: URIError: URI malformed
    at decodeURIComponent …t Object.handleFetch [as fetch] (index.js:131:23),
  message: URI malformed
}

Also, curious if I'm doing this all wrong and you know an easier way to get a base64 signature into raw bytes.

@blakeembrey
Copy link
Owner

This library converts a string to a string, I'd just use this directly instead: https://github.com/borderless/base64. It converts between ArrayBuffer directly so no need to encode/decode, which should eliminate this bug too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants