安全存储密码的最佳方法密码、方法、安全

2023-09-03 17:07:39 作者:隐形的鸡翅膀

这是对保存在计算机上的密码,以便它们不能被访问的最佳方法?我想将它们存储在加密注册表。我希望你能够重置密码,但这不是服务器。这是为将它们存储在计算机上记住它们并自动登录

What is the best method for saving passwords on a computer so that they can not be accessed? I would like to store them in the Registry encrypted. I would like you to be able to reset the password but this is not for the server. This is for storing them on a computer to remember them and sign in automatically.

重要编辑:我需要能够从程序中获取明文密码,只是没有其他地方

IMPORTANT I need to be able to retrieve the plain-text password from within the program, just not anywhere else.

推荐答案

的 CryptProtectData 和的 CryptUnprotectData 在Windows上你最好的选择。他们使用的登录凭据进行加密的数据,因此密码是从攻击到磁盘的安全。然而,它们可以通过在同一用户运行的任何程序进行访问。我建议将其存储在一个文件,其访问它们(如需要管理员权限来访问文件)的权限prevent其他程序。

CryptProtectData and CryptUnprotectData are your best bet on Windows. They encrypt the data using login credentials, so the passwords are safe from attacks to the disk. However, they can be accessed by any program running under the same user. I would recommend storing them in a file whose permissions prevent other programs from accessing them (such as a file that requires administrator privileges to access).

该管理类 ProtectedData 使用这些功能,所以它可用于从C#

The managed class ProtectedData uses these function, so it can be used from C#.

您也可以直接使用使用P / Invoke这些功能。有一些例如code,它正是这么做的这里。

You can also use these functions directly using P/Invoke. There is some example code that does exactly that here.

扩张应对额外的要求:

有一种方法,以确保你的程序是唯一一个能够访问密码,而无需你的程序将使用管理员权限启动,但它会采取更多的工作。

There is a way to ensure that your program is the only one able to access the password without needing your program to be launched with administrator privileges, though it will take a lot more work.

的基本思路是这样的:您将创建一个当您安装应用程序安装的Windows服务。应该从您的应用需求推出的时候它要存储/检索用户的密码。该服务将只提供读取设置,以便只有管理员可以读/写权限/写权限的文件。附加安全来自IPC连接到这个过程中,将使用一个命名管道。然后,您可以使用 GetNamedPipeClientProcessId (对不起,你需要的P / Invoke)来验证通过查找该连接管客户端的进程ID请求。

The basic idea is this: you create a Windows service that is installed when you install your application. It should be launched on demand from your application when it wants to store/retrieve the user's password. The service will simply provide read/write access to a file with permissions set so that only administrators can read/write it. The additional security comes from the IPC connection to the process, which will use a Named Pipe. You can then use GetNamedPipeClientProcessId (sorry, you need P/Invoke) to authenticate the request by looking up the process ID of the client that connected to the pipe.

根据你对安全有多么担心,您可以用code签名验证的进程ID,如果你有机会获得有效证书。或者,你可以验证性质的可执行文件或东西的校验。

Depending on how worried you are about security, you can verify the process ID using code signing, if you have access to a valid certificate. Or, you can verify the checksum of the executable or something of that nature.

这是我能想到的来创建你正在寻找在Windows上安全的唯一途径。您的应用程序也应该使用ProtectedData将数据移交给Windows服务,以防止硬盘袭击之前进行加密。

This is the only way I can think of to create the security you are looking for on Windows. Your application should also use ProtectedData to encrypt the data before handing it over to the Windows service to protect against hard disk attacks.