达人帮我看看这个错误

qingqing08 2008-05-13 11:03:25
  
public Byte[] EncryptEx(string Data, string Key)
{
if (Data == null || Key == null) return null;
byte[] Data_byte = Encode.GetBytes(Data);
Byte[] Output = new Byte[Data_byte.Length];
Int64 i = 0;
Int64 j = 0;
byte k;
Int16 mBoxL = 256;
Byte[] mBox = GetKey(Encode.GetBytes(Key), mBoxL);

// 加密
for (Int64 L = 0; L < Data_byte.Length; L++)
{
i = (i + 1) % mBoxL;
j = (j + mBox[i]) % mBoxL;

Byte temp = mBox[i];
mBox[i] = mBox[j];
mBox[j] = temp;

//Byte a = Data[L];
//Byte b = mBox[(mBox[i] + mBox[j] % mBox.Length) % mBox.Length];
// mBox[j] 一定比 mBox.Length 小,不需要在取模
mBox[k] =mBox[(byte)(mBox[i] + mBox[j]) % mBoxL];

Output[L] = (Byte)(mBox[k] ^ Data_byte[L]);
}

return Output;
}

public Byte[] DecryptEx(string Data, String Key)
{
return EncryptEx(Data, Key);
}

/// <returns>打乱后的S盒</returns>
static private Byte[] GetKey(Byte[] Pass,Int32 KLen)
{
Byte[] mBox = new Byte[KLen];

for (Int64 i = 0; i < KLen; i++)
{
mBox[i] = (Byte)i;
}

Int64 j = 0;
for (Int64 i = 0; i < KLen; i++)
{
j = (j + mBox[i] + Pass[i % Pass.Length]) % KLen;

Byte temp = mBox[i];
mBox[i] = mBox[j];
mBox[j] = temp;
}
return mBox;

报了三个错误
\Settings.Designer.cs
F:\coding\C\StartFrame\StartFrame\RC4Crypto.cs(16,32): 错误 CS0103: 当前上下文中不存在名称“Encode”
F:\coding\C\StartFrame\StartFrame\RC4Crypto.cs(23,34): 错误 CS0103: 当前上下文中不存在名称“Encode”
无法将类型“byte”转换为“string”

请问Data和Key都是从text中读出的string类型,如何转化为byte类型?就是1,2个错误
在最后输出的Output[]如何转化为从byte[]转化为 string类型,放进text中
...全文
74 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
大飞飞虫 2008-05-13
  • 打赏
  • 举报
回复
楼上正确,
还有一个BitConvert类提供很多静态方法可以解决很多问题
ericzhangbo1982111 2008-05-13
  • 打赏
  • 举报
回复
public string EncryptEx(string Data, string Key)
{
if (Data == null || Key == null) return null;
byte[] Data_byte = System.Text.Encoding.Default.GetBytes(Data); Byte[] Output = new Byte[Data_byte.Length];
Int64 i = 0;
Int64 j = 0;
byte k;
Int16 mBoxL = 256;
Byte[] mBox = GetKey(Encode.GetBytes(Key), mBoxL);
// 加密
for (Int64 L = 0; L < Data_byte.Length; L++)
{
i = (i + 1) % mBoxL;
j = (j + mBox[i]) % mBoxL;

Byte temp = mBox[i];
mBox[i] = mBox[j];
mBox[j] = temp;

//Byte a = Data[L];
//Byte b = mBox[(mBox[i] + mBox[j] % mBox.Length) % mBox.Length];
// mBox[j] 一定比 mBox.Length 小,不需要在取模
mBox[k] =mBox[(byte)(mBox[i] + mBox[j]) % mBoxL];

Output[L] = (Byte)(mBox[k] ^ Data_byte[L]);
}

return System.Text.Encoding.Default.GetString(OutPut);
}

public Byte[] DecryptEx(string Data, String Key)
{
return EncryptEx(Data, Key);
}

/// <returns>打乱后的S盒</returns>
static private Byte[] GetKey(Byte[] Pass,Int32 KLen)
{
Byte[] mBox = new Byte[KLen];

for (Int64 i = 0; i < KLen; i++)
{
mBox[i] = (Byte)i;
}

Int64 j = 0;
for (Int64 i = 0; i < KLen; i++)
{
j = (j + mBox[i] + Pass[i % Pass.Length]) % KLen;

Byte temp = mBox[i];
mBox[i] = mBox[j];
mBox[j] = temp;
}
return mBox;
jinjazz 2008-05-13
  • 打赏
  • 举报
回复
System.Text.Encoding.Default.GetString(b)
qingqing08 2008-05-13
  • 打赏
  • 举报
回复
那怎么把byte[]转化为string类型呢?
希望能把Output转化为string类型
jinjazz 2008-05-13
  • 打赏
  • 举报
回复
System.Text.Encoding.Default.GetBytes("ssss");


110,533

社区成员

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

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

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