java SALT 和 KEY 的区别。加密

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7303266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:28:32  来源:igfitidea点击:

Difference between SALT and KEY. Encryption

javaencryptionkeysalt

提问by cody

Alright, so im trying to learn a little about Encrypting messages in my java application. I just found out that SALT and KEY aren't the same.

好的,所以我想学习一些关于在我的 Java 应用程序中加密消息的知识。我刚刚发现 SALT 和 KEY 不一样。

Can someone help me understand what the difference between the two is?

有人可以帮助我了解两者之间的区别吗?

回答by Oliver Charlesworth

The keyis, crudely, the equivalent of a password; you use it to encrypt a message, and then the same key gets used to decrypt it back to the original plaintext. (Well, it gets a little more complex, once you have public and private keys, and so on.)

关键的是,粗制滥造,密码相当于; 您使用它来加密消息,然后使用相同的密钥将其解密回原始明文。(好吧,一旦你有了公钥和私钥,它就会变得有点复杂,依此类推。)

A saltis most typically encountered with cryptographic hashfunctions, not encryption functions. The idea is that rather than hashing just your data (e.g. a password), you hash data+salt, where salt is typically a randomly-generated string. They have (at least) two purposes:

一个是最通常遇到的加密散列函数,没有加密功能。这个想法是,不是只对您的数据(例如密码)进行散列,而是对数据+盐进行散列,其中盐通常是随机生成的字符串。他们(至少)有两个目的:

  • To foil an attacker who has access to the hashed data from identifying a collisionusing a rainbow table.
  • To slow down an attacker who's trying a brute-force attack.
  • 阻止可以访问散列数据的攻击者使用彩虹表识别冲突
  • 减慢尝试蛮力攻击的攻击者的速度。

回答by Jordaan Mylonas

The keyis essentially the password with which you lock the original content.

关键的本质是与你锁定的原始内容的密码。

To make the password more difficult to reverse engineer, you can add a saltto the produced encryption.

为了使密码更难逆向工程,您可以在生成的加密中添加



举一个明显简单的例子,假设你想加密一个字符串。你的加密例程是反转这个词。因此,对于字符串“Hello, World”,在运行加密后,您的字符串将是“dlroW ,olleH”。然后你可以往里面加盐。在这个例子中,salt 是“foo”,所以加盐后的结果是“dlroW ,olleHfoo”。现在,如果有人设法对您的加密算法进行逆向工程,他们会得到“oofHello World”,这不是原始消息,因此您的信息仍然是安全的!

This really comes into use when you iteratively encrypt, eg,
result = salt + encrypt(salt+encrypt(salt+encrypt(message))).

当您迭代加密时,这确实会派上用场,例如
result = salt + encrypt(salt+encrypt(salt+encrypt(message)))。