[英]Is it always unsecure if I pass a password as a string and not as a secure string?
I have just a general question: I don't quite understand when i have to use a secure string and when it is ok to use a normal string. 我有一个一般性的问题:我不太了解何时必须使用安全字符串,何时可以使用普通字符串。
For example lets say i want to use PrincipalContext in my application. 例如,假设我要在应用程序中使用PrincipalContext。
PrincipalContext has multiple Constructors, few of which accept a password as a string. PrincipalContext具有多个构造函数,其中很少有人接受密码作为字符串。
PrincipalContext(ContextType type, String name ,String username, String password)
Would it cause a security problem if i pass a password as a string in this constructor? 如果我在此构造方法中将密码作为字符串传递,会导致安全问题吗? Would the password be visible in plain text anywhere?
密码可以在任何地方以纯文本显示吗? Could a hacker theoretically read this password?
黑客理论上可以读取此密码吗?
Would there be a way to use a secure string instead? 是否可以使用安全字符串代替?
I am new to the security part of programming, so i would really appreciate if someone could help me understand this. 我是编程安全方面的新手,所以如果有人可以帮助我理解这一点,我将不胜感激。
Thank you! 谢谢!
If your environment (GUI, storage, data access objects, ...) supports SecureString
, then keep the passwords in SecureString as long as you can (all the way if possible). 如果您的环境(GUI,存储,数据访问对象...)支持
SecureString
,则将密码尽可能长地保留在SecureString中(如果可能,请一直使用)。 If not, there is no other choice as to use a string
. 如果不是,那么除了使用
string
之外别无选择。
Using SecureString is an advantage, because the app can control the memory containing the password and can clean it up if not used anymore (a string depends on the garbage collector). 使用SecureString 是一个优势,因为该应用程序可以控制包含密码的内存,并且如果不再使用该密码,则可以清除该密码(字符串取决于垃圾回收器)。 On the other side it gives an attacker a clue of where to look for interesting information, though with having access to the memory already this seems not to be a big thing.
另一方面,它为攻击者提供了在哪里寻找有趣信息的线索,尽管已经可以访问内存了,但这似乎并不是一件大事。
To answer your question, no it doesn't make your application unsecure, but if there is the possibility to keep the password in SecureString all the way, it should be done. 要回答您的问题,不,它不会使您的应用程序不安全,但是如果可以将密码始终保留在SecureString中,则应该这样做。
Strings are immutable and can be accessed when some other process dumps it before the Garbage collection handles it. 字符串是不可变的,当其他一些进程在Garbage集合处理它之前将其转储时,可以访问字符串 。
Reference link . 参考链接 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.