Convert Java string to byte array

前端 未结 4 1161
旧巷少年郎
旧巷少年郎 2020-12-06 01:25

I have a byte array which I\'m encrypting then converting to a string so it can be transmitted. When I receive the string I then have to convert the string back into a byte

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 01:50

    First do convertion of your byte array to proper string, by doing

    String line= new String(Arrays.toString(your_array))
    

    Then send it and use function below

    public static byte[] StringToByteArray(String line)
    {
    
        String some=line.substring(1, line.length()-1);     
        int element_counter=1;
    
        for(int i=0; i

提交回复
热议问题