import org.apache.commons.codec.binary.Hex;
public class HexEncodingExample {
public static void main(String[] args) {
byte[] encodedBytes = Hex.encodeHexString(text.getBytes());
String encodedText = new String(encodedBytes);
System.out.println("Encoded Text: " + encodedText);
byte[] decodedBytes;
try {
decodedBytes = Hex.decodeHex(encodedText.toCharArray());
String decodedText = new String(decodedBytes);
System.out.println("Decoded Text: " + decodedText);
} catch (Exception e) {
e.printStackTrace();
}
}
}
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
import org.apache.commons.codec.binary.Hex;