保护内存以防止查看
我以C#语言为Windows形式编程了一个程序,并确保它并不看到程序变量,我使用了以下三个解决方案,但是在内存中仍然使用 winhex 程序在内存中观察到一些变量。
1.用 concuserex
2.使用 securestring
3.在 app.config 的部分中输入字符串,
相关代码如下:
MAIN代码:
SecureString ss1 = ConvertToSecureString(ConfigurationManager.AppSettings["SKB"]);
byte[] SKB = System.Text.Encoding.UTF8.GetBytes(new NetworkCredential("", ss1).Password);
ss1.Dispose();
skb 在 app.config 中的值:
<appSettings>
<add key="SKB" value="0164Kfm*" />
</appSettings>
converttosecurestring()函数:
public SecureString ConvertToSecureString(string password)
{
if (password == null)
throw new ArgumentNullException("psw");
var securePassword = new SecureString();
Array.ForEach(password.ToCharArray(), securePassword.AppendChar);
securePassword.MakeReadOnly();
return securePassword;
}
通过使用winhex:
< a href =“ https://i.sstatic.net/xkwko.jpg” rel =“ nofollow noreferrer”> winhex
我如何在内存中删除变量值?
I programmed a program in Windows form in C # language and to secure it and not to see the program variables, I have used the following three solutions, but some variables are still observed in memory using the WinHex program.
1.obfuscating with ConfuserEx
2.using SecureString
3.Put the strings in the section of App.config
The related codes are as follows:
Main Code:
SecureString ss1 = ConvertToSecureString(ConfigurationManager.AppSettings["SKB"]);
byte[] SKB = System.Text.Encoding.UTF8.GetBytes(new NetworkCredential("", ss1).Password);
ss1.Dispose();
SKB's value in App.Config:
<appSettings>
<add key="SKB" value="0164Kfm*" />
</appSettings>
ConvertToSecureString() Function:
public SecureString ConvertToSecureString(string password)
{
if (password == null)
throw new ArgumentNullException("psw");
var securePassword = new SecureString();
Array.ForEach(password.ToCharArray(), securePassword.AppendChar);
securePassword.MakeReadOnly();
return securePassword;
}
The value of SKB is visible in memory by using WinHex:
How can I delete variables value in memory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论