Created
June 7, 2017 02:02
-
-
Save masters3d/a2779c9359b255bd46cd44ba9a9c88f9 to your computer and use it in GitHub Desktop.
This does not work. Simple encode & decoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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