public static byte [ ] fromString ( String str ) { ByteArrayOutputStream bs = new ByteArrayOutputStream ( ) ; byte [ ] raw = str . getBytes ( ) ; for ( int i = 0 ; i < raw . length ; i ++ ) { if ( ! Character . isWhitespace ( ( char ) raw [ i ] ) ) bs . write ( raw [ i ] ) ; } byte [ ] in = bs . toByteArray ( ) ; if ( in . length % 2 != 0 ) { return null ; } bs . reset ( ) ; DataOutputStream ds = new DataOutputStream ( bs ) ; for ( int i = 0 ; i < in . length ; i += 2 ) { byte high = ( byte ) Base16 . indexOf ( Character . toUpperCase ( ( char ) in [ i ] ) ) ; byte low = ( byte ) Base16 . indexOf ( Character . toUpperCase ( ( char ) in [ i + 1 ] ) ) ; try { ds . writeByte ( ( high << 4 ) + low ) ; } catch ( IOException e ) { } } return bs . toByteArray ( ) ; }
Convert a hex - encoded String to binary data