c# - 覆盖然后设置为空

标签 c# asp.net sql-server e-commerce pci-compliance

我在旧式电子商务平台上工作,在处理信用卡号时注意到一个惯例。 C#

cardnumber = "11111111111111111111";
cardnumber = null;

或者在 sql 中

update cards set cardnumber = '11111111111111111111' where customerid = @CustomerID
update cards set cardnumber = null where customerid = @CustomerID

我推测原因是在将其设置为 null 之前将其从内存中删除,这可能不会删除该值。但这种推理似乎表明 SQL Server 和/或 .NET VM 存在漏洞,将其设置为 null 不会完全删除数据,只是说它可用。

  1. 我的理解正确吗?
  2. 还需要吗 今天进行了吗?

最佳答案

我不知道 SQL,但在 C# 中,它没有意义。由于字符串是不可变的,因此您无法覆盖数据,即使您尽了最大努力也是如此。

当你写作时

cardnumber = "11111111111111111111";

这只是在内存中创建了另一个字符串,但是旧的卡号仍然存在于内存中的某个位置。

当你写的时候

cardnumber = null;

它取消引用先前创建的字符串,现在您有一个引用 cardnumber 指向任何内容。但是您的包含真实卡号的字符串仍然在这里。
所以这段代码不仅是错误的,而且很危险,因为它会给你一种错误的安全感。

看看 MSDN 在 SecureString 上所说的内容George Duckett 共享的页面在评论中:

An instance of the System.String class is both immutable and, when no longer needed, cannot be programmatically scheduled for garbage collection; that is, the instance is read-only after it is created and it is not possible to predict when the instance will be deleted from computer memory. Consequently, if a String object contains sensitive information such as a password, credit card number, or personal data, there is a risk the information could be revealed after it is used because your application cannot delete the data from computer memory.

进一步阅读:

关于c# - 覆盖然后设置为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16101959/

相关文章:

c# - 从多列检索数据并在单列中显示

c# - 当部分 View 与父 View 共享模型时 HtmlHelper 的奇怪行为

c# - Restful POST : Bytes to be written to the stream exceed the Content-Length bytes size specified

javascript - 回发后不显示我在 JavaScript 中右键单击显示的列表

sql - DATEPART 修复日期

sql-server - 带计数的 SQL Server Select 语句

sql - 获取SQL中单词的几个字母

c# - Xamarin 的当前上下文中不存在名称 'Log'?

c# - 为什么Angular的请求头修改会抛出option 401错误

c# - app.config configSections自定义设置找不到schema信息