Here you can find the source of toByteArray(String hex)
public static byte[] toByteArray(String hex)
//package com.java2s; //License from project: Open Source License import javax.xml.bind.DatatypeConverter; public class Main { public static byte[] toByteArray(String hex) { if (hex.length() % 2 != 0) { hex = "0" + hex; }/*from w w w.j a v a 2 s . c o m*/ return DatatypeConverter.parseHexBinary(hex); } }