Skip to content

Instantly share code, notes, and snippets.

@guiliredu
Forked from malko/urlBase64ToUint8Array.js
Created August 21, 2017 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guiliredu/dc93fe63c5b281958b89169aeeb07d52 to your computer and use it in GitHub Desktop.
Save guiliredu/dc93fe63c5b281958b89169aeeb07d52 to your computer and use it in GitHub Desktop.
used in pushManager.Subscribe to correctly encode the key to a Uint8Array
function urlBase64ToUint8Array(base64String) {
const padding = '='.repeat((4 - base64String.length % 4) % 4);
const base64 = (base64String + padding)
.replace(/\-/g, '+')
.replace(/_/g, '/')
;
const rawData = window.atob(base64);
return Uint8Array.from([...rawData].map((char) => char.charCodeAt(0)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment