mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
add Base58
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user