]>
nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/util/Hex.java
1 package org
.asamk
.signal
.util
;
5 private final static char[] HEX_DIGITS
= {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
10 public static String
toString(byte[] bytes
) {
11 StringBuffer buf
= new StringBuffer();
12 for (final byte aByte
: bytes
) {
13 appendHexChar(buf
, aByte
);
16 return buf
.toString();
19 public static String
toStringCondensed(byte[] bytes
) {
20 StringBuffer buf
= new StringBuffer();
21 for (final byte aByte
: bytes
) {
22 appendHexChar(buf
, aByte
);
24 return buf
.toString();
27 private static void appendHexChar(StringBuffer buf
, int b
) {
28 buf
.append(HEX_DIGITS
[(b
>> 4) & 0xf]);
29 buf
.append(HEX_DIGITS
[b
& 0xf]);
32 public static byte[] toByteArray(String s
) {
34 byte[] data
= new byte[len
/ 2];
35 for (int i
= 0; i
< len
; i
+= 2) {
36 data
[i
/ 2] = (byte) ((Character
.digit(s
.charAt(i
), 16) << 4) + Character
.digit(s
.charAt(i
+ 1), 16));