如何在分布式环境中存储盐

发布于 2024-11-09 18:35:34 字数 277 浏览 2 评论 0原文

我不知道如何在我的场景中使用“盐概念”。

假设我有一个客户端桌面应用程序,它为特定用户加密数据并将其发送到远程服务器。客户端应用程序使用 PKCS#5 生成密钥,其中包含用户密码和 SALT。远程桌面绝不能接触用户的密码。

假设我们为加密生成随机盐。客户端应用程序可以加密数据,并将其发送到远程服务器。如果用户尝试在另一台计算机上访问他的数据,由于盐未知,它将如何解密?

我认为始终使用相同的盐(在应用程序中硬编码)不是一个好主意(混淆的安全性很差)。

我该如何解决我的问题?

I dont know how to use the "salt concept" in my scenario.

Suppose I have a client desktop application that encrypts data for specific users and send it to a remote server. The client application generate a key with PKCS#5, with the user's password and a SALT. The remote desktop must NEVER be in contact with the user's password.

Suppose we generate a random salt for an encryption. The client application can encrypt the data, and sent it to the remote server. If the user try to access his data on another computer, how will it be able to decrypt it since the salt is unknown?

I think that using the same salt all the time (hardcoded in the application) is not a good idea (security by obfuscation is bad).

How can I solve my problem ?

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

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

发布评论

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

评论(3

行雁书 2024-11-16 18:35:40

到目前为止,我所看到的任何答案都没有涵盖分布式环境中加盐的一个方面。如果一个站点有多个需要保持同步的数据库,那么如何防止两个或多个站点几乎同时生成随机盐的竞争条件。当数据库协调一致时,如何知道给定行的哪个盐列是正确的?

恕我直言,盐值需要是不断重新计算的随机字符串的想法并没有反对使用用户行的主键(PK)之类的东西。在你惊讶地回答之前,先听我说完。

  • 任何合理的哈希函数都会产生完全不同的哈希值,无论纯文本发生多大变化(添加 1 个或 100 个字符)。
  • 如果您使用 PK,则该值独立于所有用户提供的信息。
  • 就像任何加盐操作一样,PK-as-salt 可以通过算法插入到纯文本中的任何位置。它不需要位于开头或结尾。
  • 在分布式环境中,因为没有盐柱,所以不存在关于盐柱的竞争条件。
  • 即使两个人使用相同的密码,使用像 PK 这样的隐含盐仍然会使每个哈希看起来不同。因此,PK 作为盐的想法做了盐应该做的事情,而没有协调的复杂性。

There is an aspect of salting in a distributed environment which is not being covered by any of the answers I have seen thus far. If one's site has multiple databases which need to be kept in sync, how does one guard against a race condition in which a random salt generated on two or more sites near-simultaneously. When the databases are reconciled, how's one to know which salt column for a given row is the correct one?

IMHO, the case for the idea that a salt value needs to be a constantly recalculated random string has not been made against using something like the primary key (PK) for the user row. Before you reply aghast, hear me out.

  • Any reasonable hash function will produce a completely different hash no matter how much the plain text is changes (one or 100 characters added).
  • If you use the PK then the value is independent of all user-provided information.
  • Just like any salting action, the PK-as-salt can be inserted anywhere in the plain text by the algorithm. It does not need to be at the start or end.
  • In a distributed environment, there is no race condition about the salt column because there is no salt column.
  • Using an implied salt like the PK still makes each hash look different even if two folks use the same password. Thus the PK-as-salt idea does what a salt should do without the complications of reconciliations.
你是我的挚爱i 2024-11-16 18:35:38

如果将盐包含在加密数据中,则另一台计算机上的客户端应用程序可以成功计算密码哈希。

If you include the salt with the encrypted data, then the client application on another computer can successfully compute the password hash.

凉城凉梦凉人心 2024-11-16 18:35:37

盐与加密数据一起以未加密的方式存储。

盐的目的是防止攻击者预先计算加密密码的字典。 (例如,攻击者花费一年或其他时间生成每种语言中每个单词的加密形式。)

盐的另一个目的是确保两个用户将拥有不同的加密密码,即使他们的未加密密码相同。

这两个目的都不需要盐保密。

[更新,详细说明]

请参阅Salt(密码学)的维基百科条目。特别是阅读介绍性段落。

盐的目的是获取非随机输入(例如,用户提供的数据)并在将其传递给加密函数之前使其随机。为此,必须为每个输入随机生成盐。

传统的例子是存储加密的密码。大多数用户可靠地选择非随机密码,因此如果没有盐,每个选择“SEKRIT”作为密码的人最终都会在密码数据库中获得相同的加密密码。解决方案是在加密密码之前添加随机盐,然后将其(以明文形式)与加密密码一起存储。

The salt is stored unencrypted along with the encrypted data.

The purpose of a salt is to prevent an attacker from precomputing a dictionary of encrypted passwords. (As in, the attacker spends a year or whatever generating the encrypted form of every word in every language.)

The other purpose of a salt is to make sure that two users will have different encrypted passwords even if their unencrypted passwords are the same.

Neither purpose requires that the salt remain secret.

[update, to elaborate]

See the Wikipedia entry for Salt (cryptography). In particular, read the introductory paragraphs.

The purpose of a salt is to take a non-random input (e.g., user-provided data) and make it random before passing it through a cryptographic function. For this to work, the salt must be randomly generated for each input.

The traditional example is storing encrypted passwords. Most users reliably choose non-random passwords, so without a salt, everyone who chooses "SEKRIT" as a password will wind up with the same encrypted password in the password DB. The solution is to add a random salt before encrypting the password, and then to store it (in plaintext) along with the encrypted password.

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