(Java) Base62 Encoding and Decoding
Demonstrates base62 encoding and decoding. Note: This example requires Chilkat v11.2.0 or greater.
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
CkBinData bd = new CkBinData();
// Base62 encode.
bd.AppendString("hello world","utf-8");
String base62_encoded = bd.getEncoded("base62");
System.out.println("hello world --> " + base62_encoded);
// Output:
// hello world --> AAwf93rvy4aWQVw
// Base62 decode
CkStringBuilder sb = new CkStringBuilder();
sb.DecodeAndAppend("AAwf93rvy4aWQVw","base62","utf-8");
System.out.println("decoded: " + sb.getAsString());
// Output:
// decoded: hello world
}
}
|