public class Base58Codec extends Object
encode(byte[]) and decode(String) methods are non-static
simply to accommodate possible future compatibility with Apache Commons-Codec.| Modifier and Type | Field and Description |
|---|---|
static char[] |
ALPHABET
Unfortunately, the good folks at Flickr didn't think to make the alphabet ASCIIbetical, so we can't binary-search the
byte[]. |
static BigInteger |
BASE |
static int |
BLOCK_LENGTH_BYTES
The number of whole unencoded bytes in a block of 128 Base58 digits.
|
static int |
BLOCK_LENGTH_DIGITS
The number of whole encoded Base58 digits resulting from a block of 29 bytes.
|
static Charset |
CHARSET_ASCII |
| Constructor and Description |
|---|
Base58Codec() |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
decode(String source) |
byte[] |
decode(String source,
int numBytes) |
static byte[] |
doDecode(String source)
Decode a Base58-encoded value into bytes.
|
static byte[] |
doDecode(String source,
int numBytes)
Decode a Base58-encoded value into the specified number of bytes, MSB first (with zero-padding at the front).
|
static String |
doEncode(byte[] source)
Encode a stream of MSB-ordered bytes into Base58.
|
static String |
doEncode(long value)
Convenience method to encode a
long value. |
String |
encode(byte[] source) |
String |
encode(long value) |
static byte[] |
padToSize(byte[] array,
int size)
Front-pad a byte array with zeroes or remove leading zero bytes.
|
static Iterator<Character> |
stringIterator(String string)
Provides an
Iterator over the characters in a String. |
public static final Charset CHARSET_ASCII
public static final BigInteger BASE
public static final int BLOCK_LENGTH_BYTES
public static final int BLOCK_LENGTH_DIGITS
public static final char[] ALPHABET
byte[].public static String doEncode(byte[] source)
source - the bytes to be encodedpublic String encode(byte[] source)
public static String doEncode(long value)
long value. Converts the value into a byte array and calls encode(byte[]).value - the number to be encodedpublic String encode(long value)
public static byte[] doDecode(String source)
decode(String, int) to front-pad to a specific length. If the original value encoded was negative, this
method will return a leading zero byte added as padding.source - a Base58-encoded valuepublic byte[] decode(String source)
public static byte[] doDecode(String source, int numBytes)
source - a Base58-encoded valuenumBytes - the size of the byte array to be returnedpublic byte[] decode(String source, int numBytes)
public static Iterator<Character> stringIterator(String string)
string - the string to iterate overIterator over the string's characterspublic static byte[] padToSize(byte[] array,
int size)
long or 128-bit UUID) from an encoded string, since the decoder doesn't know how wide the original input
was and only returns the number of bytes necessary to represent the decoded value, which might include a zero pad to force
the value positive.array - the array to be paddedsize - the target size of the arrayCopyright © 2019. All rights reserved.