使用Java将字符串转换为ByteBuffer,然后从ByteBuffer转换回String:
import java.nio.charset.Charset;
import java.nio.*;
String babel = "obufscate thdé alphebat and yolo!!";
System.out.println(babel);
//Convert string to ByteBuffer:
ByteBuffer babb = Charset.forName("UTF-8").encode(babel);
try{
//Convert ByteBuffer to String
System.out.println(new String(babb.array(), "UTF-8"));
}
catch(Exception e){
e.printStackTrace();
}
它先打印打印的裸字符串,然后打印转换为array()的ByteBuffer:
obufscate thdé alphebat and yolo!!
obufscate thdé alphebat and yolo!!
这对我也很有帮助,将字符串减少为原始字节可以帮助检查发生了什么:
String text = "こんにちは";
//convert utf8 text to a byte array
byte[] array = text.getBytes("UTF-8");
//convert the byte array back to a string as UTF-8
String s = new String(array, Charset.forName("UTF-8"));
System.out.println(s);
//forcing strings encoded as UTF-8 as an incorrect encoding like
//say ISO-8859-1 causes strange and undefined behavior
String sISO = new String(array, Charset.forName("ISO-8859-1"));
System.out.println(sISO);
打印解释为UTF-8的字符串,然后再次打印为ISO-8859-1:
こんにちは
ããã«ã¡ã¯