无法将sql连接字符串转换为byte []

时间:2014-08-01 19:00:42

标签: c# sql encryption cryptography bytearray

我正在尝试转换包含普通字符和' _'的sqlstring。 ,';'和' =' 当我尝试这样做时:

Byte[] byt = Convert.FromBase64String(value);

我收到此错误消息

An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll

Additional information: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

产生额外的: - 我用它来加密sqlstring 使用相同功能的-my decrypt工作正常,但在尝试转换回加密时失败

1 个答案:

答案 0 :(得分:5)

这正是你的问题

Byte[] byt = Convert.FromBase64String(value);
  

输入不是有效的Base-64字符串

您正尝试转换您未提供的base64字符串

byte[] byt = Encoding.ASCII.GetBytes(value);

转换回字符串

string value = Encoding.ASCII.GetString(byt);