]>
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
= {
6 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
12 public static String
toString(byte[] bytes
) {
13 StringBuffer buf
= new StringBuffer();
14 for (final byte aByte
: bytes
) {
15 appendHexChar(buf
, aByte
);
18 return buf
.toString();
21 public static String
toStringCondensed(byte[] bytes
) {
22 StringBuffer buf
= new StringBuffer();
23 for (final byte aByte
: bytes
) {
24 appendHexChar(buf
, aByte
);
26 return buf
.toString();
29 private static void appendHexChar(StringBuffer buf
, int b
) {
30 buf
.append(HEX_DIGITS
[(b
>> 4) & 0xf]);
31 buf
.append(HEX_DIGITS
[b
& 0xf]);
34 public static byte[] toByteArray(String s
) {
36 byte[] data
= new byte[len
/ 2];
37 for (int i
= 0; i
< len
; i
+= 2) {
38 data
[i
/ 2] = (byte) ((Character
.digit(s
.charAt(i
), 16) << 4) + Character
.digit(s
.charAt(i
+ 1), 16));