简体   繁体   English

AES解密和加密,存储在什么地方?

[英]AES Decryption and encryption, what to store and where?

I have some sensitive data that I need to store in a database, however I also need to be able to decrypt that data to its original state. 我有一些敏感数据需要存储在数据库中,但是我还需要能够将该数据解密到其原始状态。 I have been doing some reading and it seems like AES is the way to go (if you disagree then I'm more than happy to receive any suggestions!). 我一直在阅读,似乎AES是最好的选择(如果您不同意,那么我很乐意收到任何建议!)。

The thing I don't quite get with AES is that there is something called IV, and if I did get this right, IV acts like some sort of "key/password". 我用AES不太了解的是,有一种叫做IV的东西,如果我正确理解了,IV就像某种“键/密码”。

So. 所以。 My question is. 我的问题是。 If I want to decrypt the database-stored value, then do I also need to know the IV and the key to decrypt it? 如果我想解密数据库存储的值,那么我还需要知道IV和解密它的密钥吗? I would need to store these two values in the database as well? 我还需要将这两个值存储在数据库中吗?

The strength is in the Key. 力量在关键。 There's usually no problem with the IV being known , so storing it alongside the data (either as a separate column or just concatenated onto the start, as common way to do this) is fine. 有通常与IV是已知的没有问题的,所以将它存储沿着数据(或者作为一个单独的列或只是级联到开始,如常见的方法来做到这一点)是好的。

There may be some other requirement for the IV, however, that you should ensure you follow. IV可能还有其他要求,但是您必须确保遵循。 These may be around the apparent randomness of the IV, or that IVs should not be reused (although in such a case, it should more correctly be referred to as a Nonce). 这些可能围绕IV的明显随机性,或者IV不应被重用(尽管在这种情况下,应更正确地将其称为Nonce)。

IV is used for 'randomising' your data in a way that the same text never gets encrypted in the same way. IV用于以相同的文本永远不会以相同的方式加密的方式“随机化”数据。 This increases the strength of your encrypted data. 这样可以增强加密数据的强度。

Example when IV is useful: You encrypt passwords. IV有用的示例:您加密密码。 User A and User B both use the password 'HelloWorld!'. 用户A和用户B都使用密码“ HelloWorld!”。 Without and IV, the encrypted data is equal in both cases. 如果不使用和IV,则两种情况下的加密数据均相等。 If someone knows the password for User A and sees that the encrypted data is the same as for User B, he can then use the password for User A for logging in as user B. 如果某人知道用户A的密码并发现加密的数据与用户B的密码相同,则可以使用用户A的密码以用户B的身份登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM