| 188 | |
| 189 | /// Encodes the bytes as a lowercase hex string (two characters per byte). |
| 190 | public static String toHex(byte[] data) { |
| 191 | if (data == null) { |
| 192 | return null; |
| 193 | } |
| 194 | StringBuilder b = new StringBuilder(data.length * 2); |
| 195 | for (byte d : data) { |
| 196 | int v = d & 0xff; |
| 197 | b.append(HEX[v >>> 4]); |
| 198 | b.append(HEX[v & 0x0f]); |
| 199 | } |
| 200 | return b.toString(); |
| 201 | } |
| 202 | |
| 203 | /// Decodes a hex string back into bytes. The string must contain an even |
| 204 | /// number of hex characters (whitespace and the `0x` prefix are not |