mirror of
https://github.com/sparrowwallet/drongo.git
synced 2025-11-05 11:56:38 +00:00
add byte array tests for hex and base64
This commit is contained in:
parent
ca758e1288
commit
ad60a37d0e
1 changed files with 28 additions and 0 deletions
|
|
@ -52,6 +52,34 @@ public class Utils {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean isHex(byte[] bytes) {
|
||||
if(bytes == null || bytes.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(byte b : bytes) {
|
||||
if(!((b >= '0' && b <= '9') || (b >= 'A' && b <= 'F') || (b >= 'a' && b <= 'f'))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isBase64(byte[] bytes) {
|
||||
if(bytes == null || bytes.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(byte b : bytes) {
|
||||
if(!((b >= '0' && b <= '9') || (b >= 'A' && b <= 'Z') || (b >= 'a' && b <= 'z') || (b == '+') || (b == '/') || (b == '='))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String bytesToHex(byte[] bytes) {
|
||||
char[] hexChars = new char[bytes.length * 2];
|
||||
for ( int j = 0; j < bytes.length; j++ ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue