add Base58

This commit is contained in:
Looly
2022-02-25 03:18:28 +08:00
parent c3bf175b2b
commit 1c55e39832
9 changed files with 311 additions and 117 deletions

View File

@@ -4,31 +4,37 @@ import org.junit.Assert;
import org.junit.Test;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
public class Base58Test {
@Test
public void testEncode() throws NoSuchAlgorithmException {
public void encodeCheckedTest() {
String a = "hello world";
String encode = Base58.encode(a.getBytes(StandardCharsets.UTF_8));
String encode = Base58.encodeChecked(0, a.getBytes());
Assert.assertEquals(1 + "3vQB7B6MrGQZaxCuFg4oh", encode);
// 无版本位
encode = Base58.encodeChecked(null, a.getBytes());
Assert.assertEquals("3vQB7B6MrGQZaxCuFg4oh", encode);
}
@Test
public void testEncodePlain() {
public void encodeTest() {
String a = "hello world";
String encode = Base58.encodePlain(a.getBytes(StandardCharsets.UTF_8));
String encode = Base58.encode(a.getBytes(StandardCharsets.UTF_8));
Assert.assertEquals("StV1DL6CwTryKyV", encode);
}
@Test
public void testDecode() throws NoSuchAlgorithmException {
public void decodeCheckedTest() {
String a = "3vQB7B6MrGQZaxCuFg4oh";
byte[] decode = Base58.decode(a);
byte[] decode = Base58.decodeChecked(1 + a);
Assert.assertArrayEquals("hello world".getBytes(StandardCharsets.UTF_8),decode);
decode = Base58.decodeChecked(a);
Assert.assertArrayEquals("hello world".getBytes(StandardCharsets.UTF_8),decode);
}
@Test
public void testDecodePlain() {
public void testDecode() {
String a = "StV1DL6CwTryKyV";
byte[] decode = Base58.decodePlain(a);
byte[] decode = Base58.decode(a);
Assert.assertArrayEquals("hello world".getBytes(StandardCharsets.UTF_8),decode);
}
}