在开源应用程序中存储保存的密码

发布于 2024-12-02 04:55:16 字数 454 浏览 2 评论 0原文

我正在编写一个开源的 C# 应用程序,我需要能够存储每个用户保存的登录信息。通常我只会加密密码,然后将其存储在用户设置文件中,但我担心由于代码是开源的,它有点破坏了加密的意义。因为任何人所要做的就是查看代码并获取加密密钥。

诚然,这至少比以纯文本形式存储密码要困难得多。但是有没有什么好的方法可以加密密码,但即使你有源代码,解密它至少仍然非常困难?也许做到这样至少会接近 除了加密的计算机之外,不可能在任何计算机上解密?

编辑:澄清...我正在存储客户端密码,而不是用于验证其服务登录的密码。它是我无法控制的现有 Web 服务的客户端。我只想在本地存储密码以便自动登录......就像任何聊天客户端一样。

编辑2:非常抱歉之前没有说清楚。但在某些时候必须以明文形式检索密码,并且散列不是一个选项:(即使该服务让我传递密码散列,这也会有点违背目的,因为散列将与密码一样好:P

I'm writing a C# application that will be open source and I need to be able to store saved login information for each user. Normally I would just encrypt the password and then store it in a user settings file, but I worry that because of the code being open source it kind of defeats the point of encrypting it. Since all anyone would have to do is look at the code and grab the encryption key.

Granted, it would at least make it a lot harder than the password being stored in plain text. But is there any decent way of encrypting the password, but making it still at least extremely difficult to decrypt it even if you had the source? Maybe make it so it would at least be nearly
impossible to decrypt on any computer other than the one it was encrypted on?

EDIT: Clarification... I'm storing CLIENT side passwords, NOT passwords to validate their login for the service. It's a client to a pre-existing web service of which I have no control. I just want to store the passwords locally for automatic login... like any chat client would.

EDIT 2: Totally sorry for not being clear before. But passwords have to be retrieved in clear text at some point and hashing is NOT an option :( Even if the service would let me pass the password hash that would kinda defeat the purpose because the hash would be as good as a password :P

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

好久不见√ 2024-12-09 04:55:16

你问的基本上是不可能的。

如果需要解密,则没有方法可以将密码安全地存储在客户端计算机上。由于您需要它来连接到服务(我认为该服务不支持 SSL),这一事实进一步加剧了这一情况。在这种情况下,人们可以使用网络分析仪轻松找到密码。

我玩的有一个游戏(当然是闭源的)需要登录,密码保存在某处,但它使用每次安装时唯一的密钥进行加密。我忘记了一次密码,所以我只使用了 Wireshark,瞧 - 我可以看到纯密码。

这也让我想起有人抱怨 Google Chrome...他们显然不知道更多。您可以尝试所有您想要的巧妙技巧,但是一旦有人访问了计算机,任何应用程序安全性都会被抛到九霄云外。

因此,考虑到这一点,我会让加密和解密变得非常简单。最好的情况是,您可以创建一个派生自机器独有的密钥的密钥,这样某人窃取加密密码的人将无法在没有访问所述唯一密钥的情况下解密它。

What you are asking is basically, impossible.

There is no way to safely store a password on a client machine if it needs to be decrypted. This is further aggravated by the fact that you need it to connect to a service, which I presume does not support SSL. In this case, one could trivially find the password by using a network analyzer.

There is a game (closed source, of course) I play that requires a login, the password is saved somewhere but it's encrypted with a key that's unique to each install. I forgot the password once, so I just used Wireshark, and voila - I could see the plain password.

This also reminds me of people complaining about it being easy to reveal passwords in Google Chrome... They obviously don't know better. You can try all the clever tricks you want, but any application security is thrown out the window once someone has access to the machine.

So with this in mind, I would keep the encryption and decryption really simple. At best, you can create a key derived from something unique to the machine, so someone who steals the encrypted password will be unable to decrypt it without access to said unique key.

屌丝范 2024-12-09 04:55:16

如果您在 Windows 中使用此应用程序,您可以使用 DPAPI 代表用户存储敏感数据。

另外,仅存储哈希值而不是完整密码也是一个好主意!

If you are using this application in Windows you can use DPAPI for storing sensitive data on behalf of the user.

Also storing the hash only instead of the full password is a good idea!

Oo萌小芽oO 2024-12-09 04:55:16

我认为,如果您使用 Rijndal 并创建随机盐值并从机器特定的事物(如某些硬件 ID)派生密钥,即使您知道它是如何工作的,也将很难解密,因为您缺少硬件信息。

但您可能会考虑仅存储密码的哈希值并迭代至少 1000 次。哈希值无法转换回原始密码。

另一个想法:是否可以选择将实现留给使用您的源代码并使加密抽象的人?如果您提供内置捆绑包下载,当然不起作用。但话又说回来:在构建中,您可以使用自己的“秘密”加密,并仍然在源代码中抽象它。

I think if you use Rijndal for instance and create random salt values and derive the keys from machine specific things (like some hardware IDs) it will be hard to decrypt, even if you know how it works because you are missing the information of the hardware.

But you might consider storing hashes of the passwords only and iterate at least 1000 times. Hashes cannot be covnerted back to the original password.

Yet another idea: would it maybe be an option to just leave the implementation up to who ever is going use your source and make the encryption abstract? Doesn't work of course if you offer a built bundle to download. But then again: in the build you could use your own "secret" encryption and stull have it abstract in the source.

情话已封尘 2024-12-09 04:55:16

也许您可以使用某些计算机特定值(例如 mac 或 sth)来加密密码。如果有人获得源代码和加密密码,但无法完全访问计算机,则密码应该是安全的。

Maybe you can encrypt password using some machine specific values, like mac or sth.. If someone get source and encrypted password but no full access to the machine password should be safe.

淡淡の花香 2024-12-09 04:55:16

Yuo 可以使用头巾娃娃加密。您使用另一个密码加密该密码,然后使用另一个密码对其进行加密,如此反复多次,最终以明文形式写入最后一个密码。任何想要访问原始密码的人都会厌倦所有的解密并在获得原始密码之前放弃。

Yuo could use babushka doll encryption. You encryt the password with another password, then encrypt that with another password, and do that lots of times eventually writing the last password in clear text. Anyone who wants to get access to the orignal password will get sick of all the unencrypting and give up before they get to the original password.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文