Java tutorial
//package com.java2s; //License from project: Apache License public class Main { public static byte[] hexStringToByteArray(final String byteString) { String value = byteString.replaceAll("[^A-Za-z0-9]", ""); int len = value.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(value.charAt(i), 16) << 4) + Character.digit(value.charAt(i + 1), 16)); } return data; } }