android: Migrate to the Gradle build system
[strongswan.git] / src / frontends / android / app / src / main / java / org / strongswan / android / utils / Utils.java
1 /*
2 * Copyright (C) 2014 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 package org.strongswan.android.utils;
17
18
19 public class Utils
20 {
21 static final char[] HEXDIGITS = "0123456789abcdef".toCharArray();
22
23 /**
24 * Converts the given byte array to a hexadecimal string encoding.
25 *
26 * @param bytes byte array to convert
27 * @return hex string
28 */
29 public static String bytesToHex(byte[] bytes)
30 {
31 char[] hex = new char[bytes.length * 2];
32 for (int i = 0; i < bytes.length; i++)
33 {
34 int value = bytes[i];
35 hex[i*2] = HEXDIGITS[(value & 0xf0) >> 4];
36 hex[i*2+1] = HEXDIGITS[ value & 0x0f];
37 }
38 return new String(hex);
39 }
40 }