public static String toHex ( byte [ ] bytes ) { StringBuilder hexString = new StringBuilder ( ) ; for ( int i = 0 ; i < bytes . length ; i ++ ) { String hex = Integer . toHexString ( 0xFF & bytes [ i ] ) ; if ( hex . length ( ) == 1 ) { hexString . append ( ' ' ) ; } hexString . append ( hex ) ; } return hexString . toString ( ) ; }
Encode a byte array as a hexadecimal string