Programmer Corner

Hehehey.com provides this page that loaded with some handy function. You can open your browser console (often by using F12) now to use it now.

Base64 Encoding & Decoding

Encode bytes to a base64 string and back. Base64 encoded content often ends with "=".

Example:

// To encode bytes to base64 string, run:
byteArrayToBase64String(byteArray);

// To decode base64 string to bytes, run:
base64StringToByteArray("c29tZWhpbmc=");

// You can combine it with string util:
var bytes = utf8StringToByteArray("测试test");
var b64str = byteArrayToBase64String([230, 181, 139, 232, 175, 149, 116, 101, 115, 116]);
console.log(base64StringToByteArray(b64str));

String Util

Convert byte array to hex string or a utf8 string and convert it back.

Example:

// Convert string to byte array:
var byteArray = utf8StringToByteArray("测试test");

// Convert byte array to hex string:
var hex = byteArrayToHexString(byteArray);

// Convert them back:
hexStringToByteArray(hex);
byteArrayToUtf8String(byteArray);