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

How to import base64 encoded key? #31

Open
mattmazzola opened this issue May 30, 2016 · 1 comment
Open

How to import base64 encoded key? #31

mattmazzola opened this issue May 30, 2016 · 1 comment

Comments

@mattmazzola
Copy link

mattmazzola commented May 30, 2016

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.

@mahrud
Copy link

mahrud commented Dec 14, 2017

@mattmazzola Just in case this hasn't been resolved yet: JWK accepts Base64URL encoded values for x, y, and d, so probably finding a base64 conversion library that supports both modes would be easiest.

Note that besides the ='s, the URL-mode also switches _ and / to make the string URL-safe. Cf. https://en.wikipedia.org/wiki/Base64#Implementations_and_history

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