问题标签 [securestring]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - C# SecureString 问题
有没有办法在不包含安全性的情况下获得 SecureString 的值?例如,在下面的代码中,只要您执行 PtrToStringBSTR,字符串就不再安全,因为字符串是不可变的,并且垃圾回收对于字符串来说是不确定的。
如果有办法获取非托管 BSTR 字符串的 char[] 或 byte[] 怎么办?这是否意味着垃圾收集更可预测(因为您将使用 char[] 或 byte[] 而不是字符串?这个假设是否正确,如果正确,您将如何取回 char[] 或 byte[]?
c# - 使用安全字符串进行 sql 连接
我想使用 SecureString 来保存数据库的连接字符串。但是,一旦我将 SqlConnection 对象的 ConnectionString 属性设置为安全字符串的值,它肯定会对任何其他能够读取我的应用程序内存的应用程序可见吗?
我做了以下假设:
a) 我无法在托管内存之外实例化 SqlConnection 对象
b) 托管内存中的任何字符串都可以被Hawkeye等应用程序读取
c# - 使用安全字符串
这可以简化为单行吗?只要secureString被正确初始化,就可以完全重写它。
c# - Securely store a password in program code?
My application makes use of the RijndaelManaged class to encrypt data. As a part of this encryption, I use a SecureString object loaded with a password which get's get converted to a byte array and loaded into the RajindaelManaged object's Key at runtime.
The question I have is the storage of this SecureString. A user entered password can be entered at run-time, and that can be "securely" loaded into a SecureString object, but if no user entered password is given, then I need to default to something.
So ultimately the quesiton comes down to:
If I have to have some known string or byte array to load into a SecureString object each time my application runs, how do I do that? The "encrypted" data ultimately gets decrypted by another application, so even if no user entered password is specified, I still need the data to be encrypted while it goes from one app to another. This means I can't have the default password be random, because the other app wouldn't be able to properly decrypt it.
One possible solution I'm thinking is to create a dll which only spits out a single passphrase, then I use that passphrase and run it through a couple of different hashing/reorganizing functions at runtime before I ultimately feed it into the secureString object. Would this be secure enough?
Edit For clarity*: The encrypted data is being passed via files between machines. Think of it as a Zip file which always has a password, a default one is assumed if nothing is directly entered by the user.
.net - 将 SecureString 用于信用卡号
我一直在研究使用 System.Security.SecureString 类在处理信用卡号时将它们保存在内存中。有没有人使用 SecureString 类来保存信用卡号,或者大多数人只使用普通的 System.String 类?
.net - 我应该如何在 .net 中管理密码字符串?
我知道有 SecureString 类,但对于大多数情况,我认为它并没有真正有用。
例如,假设我有一个客户端/服务器系统。服务器不需要我制作的应用程序,它甚至可以是没有集成身份验证的 SQL Server。当用户在客户端应用程序的表单上输入他的密码时,它以明文形式存储在内存中,因此,虽然我可以使用 SecureString 来读取它,但我真的看不出这样做的意义。当然,它可以减少攻击面,但不多……即使我这样做了,当用户点击“OK”时,必须生成一个纯文本字符串,即使我只需要从中计算一个哈希值。
那么,在 GC 决定回收内存之前,是否有避免密码字符串浮动的方法?即使那样,内存在再次使用之前会被擦除吗?
c# - 在 ASP.NET 中使用 SecureString 有什么好处吗?
如果我理解正确,这是为了将纯文本保留在内存之外,这样应用程序就可以安全地抵御对内存、垃圾堆或分页到磁盘的内存的深奥攻击。SecureString 被馈入非托管字节并一次消耗一个非托管字节 - 然后从内存中删除该字符串。(如果我离开,请纠正我!)
在 ASP.NET 中,秘密被收集在一个 web 表单中,该表单以 HTTPS 回发。但随后 Request 对象将表单中的所有请求值转换为名称值对并将它们放入一个集合中,例如 Request["TxtPassword"]——所以即使在我得到字符串之前,它已经被不安全地写入内存。更糟糕的是,如果我使用的是控件,那么不安全的表示将在 TextBox 的属性中包含更多托管字符串。
要对这个 SecureString 做任何事情,我需要一个接受非托管字符串的 API——所以看来我不能将安全字符串用于存储的 proc 参数或其他许多参数。
我做错了还是尝试使用 SecureString 而不是将不安全字符串的副本泄漏到托管内存中是愚蠢的差事?
切换到 OAuth 或 Windows 身份验证不是一种选择。
c# - C# - compare two SecureStrings for equality
I have a WPF application with two PasswordBoxes, one for the password and another for the password to be entered a second time for confirmation purposes. I was wanting to use PasswordBox.SecurePassword
to get the SecureString
of the password, but I need to be able to compare the contents of the two PasswordBoxes to ensure equality before I accept the password. However, two identical SecureStrings are not considered equal:
I was thinking comparing the Password
property of the PasswordBoxes would defeat the point of accessing only SecurePassword
because I'd be reading the plain-text password. What should I do to compare the two passwords without sacrificing security?
Edit: based on this question, I'm checking out this blog post about "using the Marshal class to convert the SecureString to ANSI or Unicode or a BSTR", then maybe I can compare those.
c# - C# - RSACryptoServiceProvider 解密为 SecureString 而不是字节数组
我有一个当前返回从字节数组转换的字符串的方法:
我正在尝试更新此方法以返回 a SecureString
,但我无法将RSACryptoServiceProvider.Decrypt
from的返回值转换byte[]
为SecureString
。我尝试了以下方法:
但是,使用此 SecureString 相等性测试器,结果SecureString
不等于SecureString
从原始未加密文本构造的结果。我的 Encrypt 和 Decrypt 方法以前工作过,当时我只是string
到处使用,而且我还测试了SecureString
相等代码,所以我很确定这里的问题是我如何尝试转换byte[]
为SecureString
. SecureString
我应该采取另一条路线来使用 RSA 加密来让我在解密时取回 a吗?
编辑:我不想将字节数组转换为常规字符串,然后将该字符串填充到 aSecureString
中,因为这似乎首先破坏了使用 aSecureString
的意义。但是,Decrypt
返回是否也很糟糕,byte[]
然后我试图将该字节数组填充到SecureString
? 我猜如果Decrypt
返回 a byte[]
,那么这是一种传递敏感信息的安全方式,因此将数据的一种安全表示转换为另一种安全表示似乎没问题。
c# - 从我的 WPF 应用程序和 C# 库跟踪内存中的敏感数据
我一直在尝试浏览我的几个 C# 库和一个使用它们的 WPF 应用程序,并将纯文本字符串密码替换为SecureString
. 我确实必须SecureString
在某些地方将 a 转换回常规字符串以与我无法控制的其他库/Web 服务进行交互,但我想尽量减少我这样做的数量。我也试图按照这篇文章来了解如何正确地做到这一点。有没有一种简单的方法可以从我的代码中监视哪些字符串最终在内存中浮动?我想知道有多少弱点,可以这么说,我的代码中有关于敏感数据在内存中以纯文本形式存在的问题。