保护内存以防止查看

发布于 2025-01-20 19:11:17 字数 1184 浏览 3 评论 0原文

我以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:

WinHex

How can I delete variables value in memory?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文