private static readonly UnicodeEncoding bigEndianUnicode = new UnicodeEncoding(true, true);
public static string HexEncode(string stringValue)
var ba = bigEndianUnicode.GetBytes(stringValue);
var hex = new StringBuilder(ba.Length * 2);
hex.AppendFormat("{0:x2}", b);
public static string HexDecode(string hexString)
if (hexString == null || (hexString.Length & 1) == 1) return "";
var numberChars = hexString.Length;
var bytes = new byte[numberChars / 2];
for (var i = 0; i < numberChars; i += 2)
bytes[i / 2] = Convert.ToByte(hexString.Substring(i, 2), 16);
return bigEndianUnicode.GetString(bytes);
public static void Main()
var hex = HexEncode("그러하지");
var str = HexDecode(hex);
Console.WriteLine("Encoded: {0}", string.Join(",", hex));
Console.WriteLine("Decoded: {0}", str);