#code
public static void main(String[] args) {
String str = "test1234 한글포함";
System.out.println("입력 : " + str);
byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
StringBuilder result = new StringBuilder();
for (byte b : bytes) {
result.append(String.format("%02X", b));
}
String hexStr = result.toString();
System.out.println("HEX : " + hexStr);
int len = hexStr.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(hexStr.charAt(i), 16) << 4)
+ Character.digit(hexStr.charAt(i+1), 16));
}
String org = new String(data, StandardCharsets.UTF_8);
System.out.println("ORG : " + org);
}
입력 : test1234 한글포함
HEX : 746573743132333420ED959CEAB880ED8FACED95A8
ORG : test1234 한글포함