使用 AES 和密码对数据进行正确/安全的加密
现在,这就是我正在做的事情: 1. SHA-1密码,如“pass123”,使用十六进制解码的前32个字符作为密钥 2. 使用 AES-256 进行加密,无论默认参数是什么 ^这样足够安全吗?
我需要我的应用程序使用密码安全地加密数据。当我用谷歌搜索这个时,会出现太多不同的事情,还有一些我不明白的事情。我问这个问题是一个一般性问题,而不是任何特定的编码语言(尽管我计划将其与 Java 和 iOS 一起使用)。
因此,现在我正在尝试更正确地执行此操作,请按照我的想法进行操作:
输入是密码,例如“pass123”,数据是 我想要加密的内容,例如“银行帐户是038414838,密码是5931”
使用 PBKDF2 从密码中派生密钥。参数: 1000 次迭代 长度为256位 盐——这个让我很困惑,因为我不知道从哪里得到盐,我只是做一个吗?例如,我的所有加密都将始终使用盐“F”(因为显然盐是 8 位,只是一个字符)
现在我拿了这个密钥,我要散列它吗?我应该使用 SHA-256 之类的东西吗?这样安全吗?什么是 HMAC?我应该用那个吗? 注意:我是否需要同时执行步骤 2 和 3,还是只执行其中一个即可?
现在我有了 256 位密钥来进行加密。因此,我使用 AES 执行加密,但这里还有另一个令人困惑的部分(参数)。 我不太确定要使用哪些不同的“模式”,显然有 CBC 和 EBC 以及其他一些模式 我也不确定“初始化向量”,我是否只是编造一个并始终使用该向量? 那么其他选项呢?什么是 PKCS7Padding?
Right now, this is what I am doing:
1. SHA-1 a password like "pass123", use the first 32 characters of the hexadecimal decoding for the key
2. Encrypt with AES-256 with just whatever the default parameters are
^Is that secure enough?
I need my application to encrypt data with a password, and securely. There are too many different things that come up when I google this and some things that I don't understand about it too. I am asking this as a general question, not any specific coding language (though I'm planning on using this with Java and with iOS).
So now that I am trying to do this more properly, please follow what I have in mind:
Input is a password such as "pass123" and the data is
what I want to encrypt such as "The bank account is 038414838 and the pin is 5931"Use PBKDF2 to derive a key from the password. Parameters:
1000 iterations
length of 256bits
Salt - this one confuses me because I am not sure where to get the salt from, do I just make one up? As in, all my encryptions would always use the salt "F" for example (since apparently salts are 8bits which is just one character)Now I take this key, and do I hash it?? Should I use something like SHA-256? Is that secure? And what is HMAC? Should I use that?
Note: Do I need to perform both steps 2 and 3 or is just one or the other okay?Okay now I have the 256-bit key to do the encryption with. So I perform the encryption using AES, but here's yet another confusing part (the parameters).
I'm not really sure what are the different "modes" to use, apparently there's like CBC and EBC and a bunch of others
I also am not sure about the "Initialization Vector," do I just make one up and always use that one?
And then what about other options, what is PKCS7Padding?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于您的初始观点:
至于解决方案:
不要忘记在密文前面添加(随机)IV,以防您重复使用加密密钥。 IV 类似于盐,但应该恰好是 [blocksize] 字节(对于 AES 为 16)。
For your initial points:
As for the solution:
Don't forget to prepend a (random) IV to your cipher text in case you reuse your encryption keys. An IV is similar to a salt, but should be exactly [blocksize] bytes (16 for AES).