common/src/main/java/com/genexus/util/HexUtil.java
/**
         * Converts a String of hex characters into an array of bytes.
         *
         * @param s
         *            A string of hex characters (upper case or lower) of even
         *            length.
         * @param out
         *            A byte array of length at least s.length()/2 + off
         * @param off
         *            The first byte to write of the array
         */
Converts a String of hex characters into an array of bytes.
@param s
A string of hex characters (upper case or lower) of even
length.
@param out
A byte array of length at least s.length()/2 + off
@param off
The first byte to write of the array
Converts a String of hex characters into an array of bytes . @param s A string of hex characters ( upper case or lower ) of even length . @param out A byte array of length at least s . length () / 2 + off @param off The first byte to write of the array
public static final void hexToBytes(String s, byte[] out, int off)
                throws NumberFormatException, IndexOutOfBoundsException {
                int slen = s.length();
                if ((slen % 2) != 0) {
                        s = '0' + s;
                }
                if (out.length < off + slen / 2) {
                        throw new IndexOutOfBoundsException(
                                "Output buffer too small for input ("
                                        + out.length
                                        + "<"
                                        + off
                                        + slen / 2
                                        + ")");
                }
                byte b1, b2;
                for (int i = 0; i < slen; i += 2) {
                        b1 = (byte) Character.digit(s.charAt(i), 16);
                        b2 = (byte) Character.digit(s.charAt(i + 1), 16);
                        if (b1 < 0 || b2 < 0) {
                                throw new NumberFormatException();
                        }
                        out[off + i / 2] = (byte) (b1 << 4 | b2);
                }
        }
public static final void hexToBytes ( String s , byte [ ] out , int off ) throws NumberFormatException , IndexOutOfBoundsException { int slen = s . length ( ) ; if ( ( slen % 2 ) != 0 ) { s = '0' + s ; } if ( out . length < off + slen / 2 ) { throw new IndexOutOfBoundsException ( "Output buffer too small for input (" + out . length + "<" + off + slen / 2 + ")" ) ; } byte b1 , b2 ; for ( int i = 0 ; i < slen ; i += 2 ) { b1 = ( byte ) Character . digit ( s . charAt ( i ) , 16 ) ; b2 = ( byte ) Character . digit ( s . charAt ( i + 1 ) , 16 ) ; if ( b1 < 0 || b2 < 0 ) { throw new NumberFormatException ( ) ; } out [ off + i / 2 ] = ( byte ) ( b1 << 4 | b2 ) ; } }
Converts a String of hex characters into an array of bytes.
Converts a String of hex characters into an array of bytes .
// Safe to assume the string is even length