首页 \ 问答 \ AES加密 - 密钥与IV(AES Encryption - Key versus IV)

AES加密 - 密钥与IV(AES Encryption - Key versus IV)

我正在处理的应用程序让用户加密文件。 文件可以是任何格式(电子表格,文档,演示文稿等)。

对于指定的输入文件,我创建两个输出文件 - 加密数据文件和密钥文件。 您需要这两个文件才能获取原始数据。 密钥文件只能在相应的数据文件上工作。 它不应该在任何其他文件,从同一个用户或任何其他用户。

AES算法需要两个不同的加密参数,一个键和一个初始化向量(IV)。

我看到创建密钥文件的三个选择:

  1. 在应用程序中嵌入硬编码的IV,并将密钥保存在密钥文件中。
  2. 在应用程序中嵌入硬编码的密钥,并将IV保存在密钥文件中。
  3. 将密钥和IV保存在密钥文件中。

请注意,它是不同客户使用的相同的应用程序。

似乎所有三个选择都将达到同样的最终目标。 但是,我想对您应该采取哪种正确的方法提出反馈意见。


The application I am working on lets the user encrypt files. The files could be of any format (spreadsheet, document, presentation, etc.).

For the specified input file, I create two output files - an encrypted data file and a key file. You need both these files to obtain your original data. The key file must work only on the corresponding data file. It should not work on any other file, either from the same user or from any other user.

AES algorithm requires two different parameters for encryption, a key and an initialization vector (IV).

I see three choices for creating the key file:

  1. Embed hard-coded IV within the application and save the key in the key file.
  2. Embed hard-coded key within the application and save the IV in the key file.
  3. Save both the key and the IV in the key file.

Note that it is the same application that is used by different customers.

It appears all three choices would achieve the same end goal. However, I would like to get your feedback on what the right approach should be.


原文:https://stackoverflow.com/questions/9049789
更新时间:2022-11-09 20:11

最满意答案

InAppSettingKit似乎没有任何内置的客户端/服务器交互支持,因此您需要实现自己的自定义同步系统。

您的问题涉及一个非常广泛的主题,其中包含多种可能的解决方案,具有不同的复杂性,所以我只会解释如果我处于您的情况下我会如何做到这一点。

  1. 客户端

首先,我整合了像AFNetworking这样的东西,以简化向/从服务器保存和检索数据的过程。 这样您就可以轻松地将设置“发布”到服务器,并在您希望检索它们时“获取”它们。 AFNetworking非常强大,文档齐全,免费。 你可以在这里了解更多:

http://www.afnetworking.com/

每当用户进行更改时,使用AFNetworking的方法将该更改发送到驻留在服务器上的脚本以保存它。 如果要检索它,请执行GET操作。 您需要在应用程序中生成某种唯一键以引用每个用户。 如果您在应用程序中使用任何类型的登录系统,则可以将其绑定到该系统。 如果您希望用户想要从多个设备检索这些设置,您可能需要执行后者。

您还需要决定如何处理冲突的政策。 如果本地保存的设置与您从服务器提取的设置不同,您会怎么做? 如果您的用户无法访问网络,您会使用什么后备?

通常的解决方案是采取最新的(意味着您需要存储更新的时间戳) - 这可能最适合简单的需求 - 但逻辑可能会根据您的需要而有所不同。

  1. 服务器端

您将需要一个服务器端组件来处理将这些更改保存到服务器。 这可以是Node.js,Ruby,PHP等脚本,它接受服务器发送给它的输入,并将其保存在某个数据库或文件中。 这也是一个广泛的主题,实际上取决于您的编程背景在服务器端。

注意:您应该考虑这种设置的安全性需求,尽管如果保存的设置完全不敏感,这可能是最小的。 否则,您需要采取适当措施来保护数据(SSL / TLS,salting / hashing密码等)。

  1. 你需要这个吗?

你在问题中特别提到了“web服务器”,所以我假设你有自己的服务器,并且很乐意为它编写代码(或者愿意学习如何)。 这就是我编写自己的客户端/服务器代码的方式,它有很多优点,但如果你所做的只是保存一些设置,那么你的需求可能会有些过分。

在iOS 8中,Apple推出了一个名为CloudKit的简化iCloud系统。 它将所有内容与用户的iCloud帐户联系起来,并且设计简单。 如果你所做的只是同步一些简单的设置,你可以使用CloudKit的键/值存储来为你处理。

CloudKit有一些缺点。 存储的数据是不透明的(例如,您将无法从Web应用程序或Android应用程序访问它),仅限于iOS 8及更高版本,如果您的应用非常适用,可能会花费您一定的金额,非常受欢迎。 但是,对于简单的设置同步,这可能完全适合您的需求。

CloudKit定价(可能对您免费):

https://developer.apple.com/icloud/documentation/cloudkit-storage/

有关CloudKit的WWDC视频:

https://developer.apple.com/videos/wwdc/2014/?id=208

https://developer.apple.com/videos/wwdc/2014/?id=231

CloudKit设计指南:

https://developer.apple.com/library/ios/documentation/General/Conceptual/iCloudDesignGuide/Chapters/Introduction.html

CloudKit框架参考:

https://developer.apple.com/library/ios/documentation/CloudKit/Reference/CloudKit_Framework_Reference/index.html

我希望这有帮助。


It doesn't appear that InAppSettingKit has any built-in support for client/server interaction, so you'll need to implement your own custom synchronization system.

Your question touches on a very broad topic with more than a few possible solutions with varying complexity, so I'll just explain how I'd do it if I were in your situation.

  1. CLIENT-SIDE

First, I'd integrate something like AFNetworking to simplify the process of saving and retrieval of data to/from the server. This will allow you to easily 'POST' your settings to the server and 'GET' them when you wish to retrieve them. AFNetworking is incredibly powerful, well-documented and free. You can learn more here:

http://www.afnetworking.com/

Whenever a user makes a change, use AFNetworking's methods to POST that change to a script residing on your server that saves it. When you wish to retrieve it, perform a GET operation. You'll need to generate some sort of unique key in the app to reference each user. If you use a login system of any sort in your app, you can tie it to that. You'll probably need to do the latter if you expect users to want to retrieve these settings from multiple devices.

You'll also need to decide upon a policy on how to handle conflicts. If the locally-saved settings differ from what you pull from the server, what do you do? What fallback do you use if your user is not able to access the network?

The usual solution is to just take whatever is more recent (meaning you'll need to store a timestamp for updates) - and this is probably most appropriate for simple needs - but the logic may differ depending on your needs.

  1. SERVER-SIDE

You will need a server-side component to handle saving these changes to the server. This could be a Node.js, Ruby, PHP, etc. script that takes the input sent to it by the server and saves it either in a database or file somewhere. This, too, is a broad topic and really depends on what your programming background is on the server-side.

Note: You should consider the security needs of such a setup, although this could be minimal if the settings being saved aren't at all sensitive. Otherwise, you will need to take appropriate measures to secure the data (SSL/TLS, salting/hashing passwords, etc).

  1. DO YOU NEED THIS?

You specifically mentioned "web server" in your question, so I assumed that you have your own server and are comfortable writing code for it (or willing to learn how). This is how I write my own client/server code and it has many advantages, but could be overkill for your needs if all you're doing is saving some settings.

With iOS 8 Apple introduced a simplified iCloud system called CloudKit. It ties everything to the user's iCloud account and is designed to be simple to set up. If all you're doing is syncing some simple settings you could use CloudKit's key/value storage to handle that for you.

There are some downsides to CloudKit. The stored data is opaque (ie. you won't be able to access it from a web app or an Android app, for instance), is limited to iOS 8 and newer and may cost you a nominal amount if your app is very, very popular. For simple settings synchronization, though, this may be wholly appropriate to your needs.

CloudKit pricing (probably free to you):

https://developer.apple.com/icloud/documentation/cloudkit-storage/

WWDC videos about CloudKit:

https://developer.apple.com/videos/wwdc/2014/?id=208

https://developer.apple.com/videos/wwdc/2014/?id=231

CloudKit design guide:

https://developer.apple.com/library/ios/documentation/General/Conceptual/iCloudDesignGuide/Chapters/Introduction.html

CloudKit framework reference:

https://developer.apple.com/library/ios/documentation/CloudKit/Reference/CloudKit_Framework_Reference/index.html

I hope this helps.

相关问答

更多
  • 您无法将自定义元素添加到appSettings 。 实现自定义格式的最佳方法是编写自己的ConfigurationSettings类并在配置中使用它。 这将允许您以强类型的方式存储数据以及具有有意义的元素和属性名称。 请参阅如何:在MSDN上使用ConfigurationSection创建自定义配置部分 。 You can't add custom elements to appSettings. The best way to achieve a custom format it to write you ...
  • InAppSettingKit似乎没有任何内置的客户端/服务器交互支持,因此您需要实现自己的自定义同步系统。 您的问题涉及一个非常广泛的主题,其中包含多种可能的解决方案,具有不同的复杂性,所以我只会解释如果我处于您的情况下我会如何做到这一点。 客户端 首先,我整合了像AFNetworking这样的东西,以简化向/从服务器保存和检索数据的过程。 这样您就可以轻松地将设置“发布”到服务器,并在您希望检索它们时“获取”它们。 AFNetworking非常强大,文档齐全,免费。 你可以在这里了解更多: http:/ ...
  • 无需特殊设置。 Sencha Touch基本上是一个包含在HTML中的Javascript文件。 将它们添加到您的公共目录(默认为htdocs),然后将其添加到您的HTML文件中,然后开始使用Sencha Touch API进行编程! No ...
  • 你在谈论两件事; 1)如果/何时离线(存储机制)如何存储/保存数据,以及2)如何在线时与服务器同步(通信机制)。 1的答案是某种本地存储,根据您的平台,有几种方法(localstorage,websql,文件系统API等)。 2的答案实际上取决于您的同步需求有多紧急,但一般情况下,您可以使用HTTP本身进行定期(长)轮询,websockets等。 除了存储和通信机制之外,还有许多库可以简化工作,如Meteor(通信)和CouchDB(存储),还有许多其他库。 甚至有一些库可以处理实际的同步机制(也可能有冲突 ...
  • 我经常看到这使用配置数组完成: $config["admin_email"] = "admin@mydomain.com"; $config["site_name"] = "Bob's Trinket Store"; $config["excluded_modules"] = array("inventory", "user_chat"); 然后你可以检查: if (!in_array("inventory", $config["excluded_modules"])) { // include in ...
  • 安全确实是一个非常广泛的话题。 没有简短的答案。 无论如何,Web服务和客户端应用程序都需要实现安全机制。 我建议,您提供Web服务和客户端应用程序。 您可能需要使用密码进行一些用户登录,“服务器验证用户身份”和“客户端使用证书验证服务器身份”。 然后使用HTTPS确保以安全的方式传输可靠的数据。 Web服务应该使用一个众所周知的Web应用程序框架来实现,因为安全性是一个可怕的业务,而且很棘手。 自己实现所有内容,可能会以次优的不安全应用程序结束。 您现在应该阅读有关复杂主题的更多信息,并在遇到具体问题时再 ...
  • 当然,您需要使用chrome.sockets.tcpServer api ,它允许您使用TCP连接创建服务器应用程序。 例如,看一下chrome-app-samples-webserver 。 Sure, you would need to use chrome.sockets.tcpServer api, it allows you to create server applications using TCP connections. And for examples, take a look at c ...
  • 我相信这是由制造商完成的。 我在几部手机上看过它。 如果你扎根,尝试使用不同的ROM(如cyanogen)。 Well, I figured it out myself (Duh), it was operator error. The answer is that I didn't understand how download-install works. After downloading APK, I had to go to "Downloads" on my phone and select t ...
  • 根据您的描述,如果您想启用“WEBSITE_HTTPLOGGING_RETENTION_DAYS”和“WEBSITE_HTTPLOGGING_CONTAINER_URL”,我建议您尝试使用azure Resource Explorer来更改插槽设置。 更多细节,您可以按照以下方式。 1.打开azure Resource Explorer并找到您的Web应用程序。 2.打开Web应用程序的slotConfigNames标记。 3.在属性中添加appsetting名称。 首先单击编辑并更改属性。 最后单击put ...
  • 由于代码作为服务运行,因此基础System.Net库在这种情况下不会使用Internet设置值。 对于在.config文件中没有特定设置的情况下如何派生代理设置的细节,MS有点粗略。 以下是一些尝试: - 一个命令行使用: - ProxyCfg -d 这将删除WinHTTP组件使用的任何代理设置(设计为在.NET出现之前通过代码在这样的服务器设置中使用)。 ProxyCfg -u 将当前用户的Internet代理设置复制到WinHTTP使用的系统范围设置。 更好的是在调用应用程序的web.confi ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)