Skip to content

Instantly share code, notes, and snippets.

@masters3d
Created June 7, 2017 02:02
Show Gist options
  • Save masters3d/a2779c9359b255bd46cd44ba9a9c88f9 to your computer and use it in GitHub Desktop.
Save masters3d/a2779c9359b255bd46cd44ba9a9c88f9 to your computer and use it in GitHub Desktop.
This does not work. Simple encode & decoder
// This would be hosted on the server but node does not support atob btoa.
function decode(toDecode){ // eslint-disable-line no-unused-vars
let salt = 'MySimpleSalt';
let decoded = atob(toDecode);
if (toDecode === btoa(decoded)){
return decoded.replace(salt,'');
}
throw new Error('Could not decode data');
}
function encode(toEncode){ // eslint-disable-line no-unused-vars
let salt = 'MySimpleSalt';
let encoded = btoa(toEncode + salt);
if ((toEncode + salt) === atob(encode)){
return encoded;
}
throw new Error('Could not encode data');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment