简体   繁体   English

如果我将密码作为字符串而不是安全字符串传递,是否总是不安全?

[英]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.

相关问题 连接字符串中的用户名和密码如何安全? - How secure the user name and password in the connection string? 混合安全和不安全的渠道 - Mixing secure & unsecure channels 如何以不安全的代码连接和哈希用户名和密码(存​​储在安全字符串中) - How to concatenate and hash a username and password (stored in a secure string) in unsafe code 使用ADO.NET实体数据模型,如何传递(或设置)连接字符串密码? - Using ADO.NET Entity Data Model, how do I pass (or set) the connection string password? 我能够将用户名和密码传递给Web服务,但这不是我需要防止未经授权的用户访问的方式 - I was able to pass username and password to webservice, but its not the way i need to secure from unauthorized user 将StringBuilder转换为安全字符串 - Convert StringBuilder to Secure String 将字符串变量传递到Nework凭证构造函数中以进行密码辩论 - Pass String Variable Into Nework Credential Constructor for Password Arguement 加密/保护短字符串到长字符串 - Encrypt / secure short string to long 工作角色中的安全连接字符串 - Secure connection string in Worker Role 如何从UserInput保护字符串 - How to Secure a string from UserInput
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM