private static byte [ ] convertClearTextToByteArray ( String clearText ) { byte [ ] result = new byte [ clearText . length ( ) * 2 ] ; for ( int i = 0 ; i < clearText . length ( ) ; i ++ ) { char thisChar = clearText . charAt ( i ) ; int pos = i * 2 ; result [ pos ] = ( byte ) ( thisChar >>> 8 & 0xFF ) ; result [ pos + 1 ] = ( byte ) ( thisChar & 0xFF ) ; } return result ; }
Convert the clear text to a byte array by splitting each 16 - bit character into 2 bytes . This insures that no data is lost .