gpt4 book ai didi

c# - .net MVC 中的 key 和 IV 存储位置在哪里?

转载 作者:行者123 更新时间:2023-11-30 23:10:18 24 4
gpt4 key购买 nike

我有 asp.net MVC 5 项目并加密用户敏感信息并存储在数据库中,当我向用户显示数据时从数据库中获取信息并解密(在 mvc 项目中加密/解密并将数据加密存储在数据库中)。

我使用 AesCryptography 加密/解密数据。我有Key和IV,key和IV的存放位置在哪里?

必须保存在 webconfig 中或在数据库中创建一个包含 Key 和 Iv 列的单独表,或者将 Key/IV 列添加到用户表。

为每一行数据创建一个键和 Iv 是个好主意吗?

最佳答案

您应该将 key 存储在 web.config 中。使用 appSettings 作为最简单的方法,完全没问题。

  <appSettings>
<add key="DataEnryptionKey" value="allyourbase"/>
</appSettings>

维基百科:

An initialization vector has different security requirements than a key, so the IV usually does not need to be secret. However, in most cases, it is important that an initialization vector is never reused under the same key.

IV 的全部要点是对于每个加密操作都是不同的。所以当你对“123”加密两次时,你不会得到相同的加密输出。参见维基。

所以在web.config中存放IV是不行的。通用方法 - 将 IV 存储为第一个密码 block 。

简单的方法

使用MachineKey.Protect/MachineKey.Unprotect 方法他们已经以安全的方式做事。

您只需使用 IIS 或其他工具生成 key 。


enter image description here


enter image description here

关于c# - .net MVC 中的 key 和 IV 存储位置在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45432117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com