This Base62 variant treats bytes as a big-endian integer and writes it with the fixed alphabet 0-9A-Za-z. Leading zero bytes become leading 0 characters so decoding reconstructs the original byte sequence.
Use Base62 for compact, punctuation-free identifiers in URLs or databases. Base62 has no universal standard, so alphabet order and leading-zero rules must match; this reversible encoding is neither a hash nor encryption and includes no checksum.
// npm install base-x
import basex from 'base-x';
const base62 = basex('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
const encoded = base62.encode(Buffer.from('Hello'));
console.log(encoded);
// Output: 5TP3P3v
const decoded = Buffer.from(base62.decode('5TP3P3v')).toString('utf8');
console.log(decoded);
// Output: Hello
package main
import (
"fmt"
"github.com/eknkc/basex"
)
func main() {
base62, _ := basex.NewEncoding("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
encoded := base62.Encode([]byte("Hello"))
fmt.Println(encoded)
// Output: 5TP3P3v
decoded, _ := base62.Decode(encoded)
fmt.Println(string(decoded))
// Output: Hello
}
<?php
// composer require tuupola/base62
require 'vendor/autoload.php';
$base62 = new Tuupola\Base62;
$encoded = $base62->encode("Hello");
echo $encoded . "\n";
$decoded = $base62->decode($encoded);
echo $decoded . "\n";
// Output: Hello