public static byte [ ] fromString ( final String pData ) { if ( pData == null ) { throw new IllegalArgumentException ( "Argument can't be null" ) ; } StringBuilder sb = new StringBuilder ( pData ) ; int j = 0 ; for ( int i = 0 ; i < sb . length ( ) ; i ++ ) { if ( ! Character . isWhitespace ( sb . charAt ( i ) ) ) { sb . setCharAt ( j ++ , sb . charAt ( i ) ) ; } } sb . delete ( j , sb . length ( ) ) ; if ( sb . length ( ) % 2 != 0 ) { throw new IllegalArgumentException ( "Hex binary needs to be even-length :" + pData ) ; } byte [ ] result = new byte [ sb . length ( ) / 2 ] ; j = 0 ; for ( int i = 0 ; i < sb . length ( ) ; i += 2 ) { result [ j ++ ] = ( byte ) ( ( Character . digit ( sb . charAt ( i ) , 16 ) << 4 ) + Character . digit ( sb . charAt ( i + 1 ) , 16 ) ) ; } return result ; }
Method to get bytes form string