Skip to content

Instantly share code, notes, and snippets.

@icodealot
Created September 26, 2017 21:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save icodealot/0f24f4e322c15d2c8558751cba1ea0d5 to your computer and use it in GitHub Desktop.
Save icodealot/0f24f4e322c15d2c8558751cba1ea0d5 to your computer and use it in GitHub Desktop.
// This is a minimal Base64 encode/decode utility for Nashorn -> JavaScript
// Add error checking for data types as needed within encode or decode
var Base64 = {
decode: function (str) {
return new java.lang.String(java.util.Base64.decoder.decode(str));
},
encode: function (str) {
return java.util.Base64.encoder.encodeToString(str.bytes);
}
};
print(Base64.decode(Base64.encode("Hello, World!")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment