安全存储 AES 密钥
我在一个程序中使用 OpenSSL,该程序解密文本文件,然后在每次程序启动时使用新文本和新加密密钥重新加密它。我想在运行的程序实例之间安全地存储密钥。有没有一种简单/相当安全的方法来做到这一点?
I'm using OpenSSL in a program that decrypts a text file and then re-encrypts it with new text and a new encryption key every time the program starts. I'd like to safely store the key between instances of the program running. Is there an easy/decently safe way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您预计安装应用程序的计算机不会受到硬核攻击,您始终可以在应用程序内硬编码另一个您将使用的加密密钥,以便安全地保存先前的会话
AES
在您关闭应用程序之前在文件系统中键入密钥,并在您启动应用程序时检索它。如果满足以下条件,您可以稍微提高安全性:您不将编码密钥存储到单个字符串中,而是将其存储在多个字符串中,然后在函数中连接
将文件保存在相对“未知”/不受欢迎的位置,例如独立存储或 Windows\Temp,而不是应用程序文件夹
您使用 asimetric 密钥算法(使破解更加困难......但在这种情况下......只是一点点)
你在文件中放入了其他东西(伪造的)而不仅仅是密钥
If you don't expect hard core attacks on the machine that the application is installed on, you can always hardcode inside your application another encryption key that you would use in order to safely save the previous session
AES
key in the file system before you close the app and to retrieve it back when you start the app. You could improve a bit the security if:you don't store the harcoded key into a single string, but instead in several strings that you then concatenate in a function
you save the file in a relatively "unknown"/unpopular location like the Isolated Storage, or Windows\Temp instead of the application folder
you use an asimetric key algorithm (makes cracking harder.. but in this case.. just a little bit)
you put other stuff (bogus) in the file not just the key
如果您的程序不在安全区域(如果可以检查其二进制代码以找到它包含的任何密钥或它定义的任何算法),则没有简单的方法:
您可以以编程方式混淆您的密钥并将其存储在一个文件,但在这种情况下,破坏你的混淆算法就足以找到密钥。因此,这实际上会降低该算法的加密强度。这不是一个好方法。
您还可以使用程序中嵌入的静态密钥(称为 B)来加密密钥(此处称为 A)本身,但在这种情况下,您将失去每次更改密钥 A 的兴趣。这是因为找到嵌入在程序中的密钥 B 就足以找到保存到磁盘上的任何加密密钥 A。这也不能令人满意。
考虑更复杂的解决方案需要更多地了解您的上下文(攻击来自哪里,文件的生命周期是什么,等等)。但在走那么远之前……有必要走那么远吗?我的意思是:您的程序是否面临破解尝试的风险?它应该被破解吗?它那么重要吗?如果不可破解或不重要,上面的第二个选项就足够了。
If your program is not in a safe area (if its binary code can be inspected to find any key it would contain or any algorithm it would define) there is no simple way:
You could obfuscate your key programmatically and store it in a file, but in that case, breaking your obfuscation algorithm would be sufficient to find the key. So this would reduce the strengh of the encryption to that algorithm, actually. Not a good way to go.
You could also encrypt the key (called A here) itself, using a static key (called B) embedded in your program, but in that case, you would lose the interest of changing the key A every time. This because finding the key B embedded in your program would be sufficient to find any encrypted key A saved to the disk. This would not be satisfactory either.
Considering more complex solutions requires knowing your context a bit more (where can the attack come from, what is the lifecycle of the file, etc). But before going that far... is it needed to go that far? By this I mean: is your program at risk of cracking attempts? And should it be cracked, it that criticial? If not crackable or not critical, the second option above should be sufficient.
如果您的目标主机具有 TPM 芯片,您就可以利用它。借助 trousers 项目,可以将 OpenSSL 配置为使用 TPM
If your target host has a TPM chip, you can take advantage of it. OpenSSL can be configured to use TPM, with the help of trousers project