diafygi / diafygi/webcrypto-examples
How to import base64 encoded key?
- Dominant language
- HTML
- Stars
- 1.7k
- Forks
- 191
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I was experimenting with your examples to try to recreate a browser version of:
https://www.npmjs.com/package/jwt-simple
Here is a gist to explain end goal (although this gist doesn't work):
https://gist.github.com/mattmazzola/1eafd7aea79e082982da203ec0405997
When attempting to import the key I am receiving the error:
`undefined:1 Uncaught (in promise) DOMException: The JWK member "k" could not be base64url decoded or contained padding`
I was using this example: https://github.com/diafygi/webcrypto-examples#hmac---importkey
I know the trailing equal signs indicate there is padding on the key `==`, but I'm not sure how to remove it and still import using the same method. It seems like I would have to convert it to an ArrayBuffer and then remove the trailing 0's somehow, but then if we have to use raw key import it makes using jwk seems less useful and I thought there must be a better way or perhaps the import jwk should just handle this for us.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.