c#从加密码狗读出来的十六进制串,怎么转换成字符串

netxie 2008-09-19 11:27:45
原串:

以已之心,斗其之智AaBbCcXxZz

十六进制串:

D2D4D2D1D6AED0C4A3ACB6B7C6E4D6AED6C741614262436358785A7A
...全文
275 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
wdgphc 2008-09-19
  • 打赏
  • 举报
回复
        static void Main(string[] args)
{
Console.WriteLine(GetValue("以已之心,斗其之智AaBbCcXxZz"));
Console.ReadKey();
}
static string GetValue(string str)
{
string s = "";
byte[] bs = Encoding.GetEncoding("GB2312").GetBytes(str);
foreach (byte b in bs)
s += b.ToString("X2");
return s;
}

QIHONGWEI_2000_0 2008-09-19
  • 打赏
  • 举报
回复
string GetValue(string sHex)
{

string str="";
Encoding enc = Encoding.GetEncoding("GB2312");
for(int i=0; i < sHex.Length - 3; i +=4)
{
string sub = sHex.Substring(i,4);

//byte order is wrong, need to do a switch
sub = sub.Substring(2,2) + sub.Substring(0,2);

int c = int.Parse(sub,System.Globalization.NumberStyles.HexNumber);
byte[] bs = BitConverter.GetBytes(c);


str=str+enc.GetString(bs).Replace("\0","");
}

return str;
}
wdgphc 2008-09-19
  • 打赏
  • 举报
回复
42 62 43 63 58 78 5A 7A
A a B b X x Z z

看来字母很容易啊.
netxie 2008-09-19
  • 打赏
  • 举报
回复
回复有分,楼是不是编码引起的?
netxie 2008-09-19
  • 打赏
  • 举报
回复
TO:the2ndface

以 已 之 心 ,斗 其 之 智 Aa Bb Cc Xx Zz
QIHONGWEI_2000_0 2008-09-19
  • 打赏
  • 举报
回复
byte []dataBuff; 放十六进制串
string str="";
for(int i=0;i<DataBuff.Length;i++)
{
str=str+Convert.toString(DataBuff[i])
}
Wesley 2008-09-19
  • 打赏
  • 举报
回复
好像这只是对汉字的。。。我也不是很理解,帮顶
  • 打赏
  • 举报
回复
这个需要用加密狗的解密方法吧?
Wesley 2008-09-19
  • 打赏
  • 举报
回复
  using   System.Text;  

string GetValue(string sHex)
{
StringBuilder sb = new StringBuilder();
Encoding enc = Encoding.GetEncoding("GB2312");
for(int i=0; i < sHex.Length - 3; i +=4)
{
string sub = sHex.Substring(i,4);

//byte order is wrong, need to do a switch
sub = sub.Substring(2,2) + sub.Substring(0,2);

int c = int.Parse(sub,System.Globalization.NumberStyles.HexNumber);
byte[] bs = BitConverter.GetBytes(c);

sb.Append(enc.GetString(bs));
}

return sb.ToString();
}


Console.Write(GetValue("B2DDD2B6"));


这也是我引用别人的,希望对LZ有帮助
wuyi8808 2008-09-19
  • 打赏
  • 举报
回复
多给些例子才好推测。
nattystyle 2008-09-19
  • 打赏
  • 举报
回复
前排接分
wdgphc 2008-09-19
  • 打赏
  • 举报
回复
11楼的写反了,通过byte转string的如下,很简单

        static void Main(string[] args)
{
Console.WriteLine(ByteToString("D2D4D2D1D6AED0C4A3ACB6B7C6E4D6AED6C741614262436358785A7A"));
Console.ReadKey();
}

static string ByteToString(string str)
{
string[] s =System.Text.RegularExpressions.Regex.Replace(str, @"\w{2}", @"$0 ").Trim().Split(' ');
byte[] bs = new byte[s.Length];
for (int i = 0; i < s.Length; i++) bs[i] = Convert.ToByte(s[i], 16);
return Encoding.GetEncoding("GB2312").GetString(bs);
}
yagebu1983 2008-09-19
  • 打赏
  • 举报
回复
不知道加密算法啊!
bbbbbb888888 2008-09-19
  • 打赏
  • 举报
回复
ding 12L
  • 打赏
  • 举报
回复
学习下
onekey 2008-09-19
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 hhhh63 的回复:]
string strhex = "D2D4D2D1D6AED0C4A3ACB6B7C6E4D6AED6C741614262436358785A7A";
int n = strhex.Length / 2;
byte[] buf = new byte[n];
for( int i = 0; i < n; i++ )
buf[i] = byte.Parse( strhex.Substring( i*2, 2 ), System.Globalization.NumberStyles.HexNumber );

Encoding enc = Encoding.GetEncoding("GB2312");
string str = enc.GetString( buf );
Console.Write( str );

我做加密狗的时候,读…
[/Quote]

这个可以
春天的气息 2008-09-19
  • 打赏
  • 举报
回复
怎么加的就怎么解呀,
JeffChung 2008-09-19
  • 打赏
  • 举报
回复
12楼的看起来不错,楼主试试
tianjinldl 2008-09-19
  • 打赏
  • 举报
回复
你指的是显示未加密前的串么,这个没有解密算法行么
hhhh63 2008-09-19
  • 打赏
  • 举报
回复
string strhex = "D2D4D2D1D6AED0C4A3ACB6B7C6E4D6AED6C741614262436358785A7A";
int n = strhex.Length / 2;
byte[] buf = new byte[n];
for( int i = 0; i < n; i++ )
buf[i] = byte.Parse( strhex.Substring( i*2, 2 ), System.Globalization.NumberStyles.HexNumber );

Encoding enc = Encoding.GetEncoding("GB2312");
string str = enc.GetString( buf );
Console.Write( str );

我做加密狗的时候,读出来的直接就是字节数组,那就更简单了。
byte[] buf = new byte[]{ 0xD6, 0xC7, 0x41 }; //加密狗二进制数据
Encoding enc = Encoding.GetEncoding("GB2312");
string str = enc.GetString( buf );
Console.Write( str );

以上 .net2003测试通过。

110,565

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧