VanillaJS, Lightweight, Zero-Dependency, PEM (RFC 7468) encoder and decoder.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

23 lines
421 B

'use strict';
// "A little copying is better than a little dependency" - Rob Pike
var Enc = module.exports;
Enc.bufToBase64 = function(u8) {
var bin = '';
// map is not part of u8
u8.forEach(function(i) {
bin += String.fromCharCode(i);
});
return btoa(bin);
};
Enc.base64ToBuf = function(b64) {
return Uint8Array.from(
atob(b64)
.split('')
.map(function(ch) {
return ch.charCodeAt(0);
})
);
};