43 lines
1.0 KiB
C#
43 lines
1.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace KDCS.Utils
|
|
{
|
|
public class Crypt
|
|
{
|
|
|
|
|
|
static public string str2hex(string strData)
|
|
{
|
|
string resultHex = string.Empty;
|
|
byte[] arr_byteStr = Encoding.Default.GetBytes(strData);
|
|
|
|
foreach (byte byteStr in arr_byteStr)
|
|
resultHex += string.Format("{0:X2}", byteStr);
|
|
|
|
return resultHex;
|
|
}
|
|
|
|
static public string HexString2Ascii(string hexString)
|
|
{
|
|
byte[] tmp;
|
|
int j = 0;
|
|
int lenght;
|
|
lenght = hexString.Length - 2;
|
|
tmp = new byte[(hexString.Length) / 2];
|
|
for (int i = 0; i <= lenght; i += 2)
|
|
{
|
|
tmp[j] = (byte)Convert.ToChar(Int32.Parse(hexString.Substring(i, 2), System.Globalization.NumberStyles.HexNumber));
|
|
j++;
|
|
}
|
|
return Encoding.Default.GetString(tmp);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|