我怎样才能保护字符串,例如C#

How can i secure Strings in e.g. C#

是否可以在 C# 中保护字符串以防止...我称之为 "String Attacks"?

这是一个示例:

...
const String username = "friend";
const String password = "letmein";
String encoded = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));

WebRequest request = WebRequest.Create("http://xxx.xxx.xxx.xxx/");
WebResponse response = request.GetResponse();

Stream dataStream = response.GetResponseStream();  
StreamReader reader = new StreamReader(dataStream); 
string responseFromServer = reader.ReadToEnd(); 

lbl_status.Text = responseFromServer;

reader.Close();  
response.Close();
...

如果我编译 & 运行 它,我可以使用 Sysinternals Process Explorer 读取存储的字符串。

有没有加密字符串的方法?

你好莫

谢谢@Alejandro!

我的问题的答案是 "NO"。

That's why you should never hardcode passwords in source code.