如何安全存储密钥? [英] How to safely store secret key?

查看:1209
本文介绍了如何安全存储密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用使用haxe的openFL开发应用程序时,并且我即将开始软件的激活部分,我想知道如何安全地存储我的加密密钥?我可以将其硬编码到我的应用程序中吗?!

As I have developed my app using openFL which uses haxe, and I am about to start the activation part of my software, I wonder how would I safely store my encryption secret key? would I just hard code it into my app??!

在将其发送到服务器之前,我将使用此密钥对数据进行加密,并且还将对从服务器接收的数据进行解密.

I will be using this key to encrypt data before sending to server, and I will be using it to de-encrypt data received from server too.

在这种情况下,任何人都可以推荐最佳做法吗?

Any one can recommend best practices followed in such case?

推荐答案

这听起来像是非对称加密的工作.

This sounds like a job for asymmetric encryption.

  1. 在服务器上创建密钥对,存储公用密钥和专用密钥.私钥应保持安全,密钥大小应为2048位或更多;
  2. 在您的应用程序中包含公钥;
  3. 应用程序使用安全的随机生成器来创建AES密钥;
  4. 使用CBC和PKCS#7填充对数据进行加密,还包括HMAC(可能还带有另一个随机AES密钥);
  5. 使用RSA算法和公钥对密钥进行加密;

服务器现在可以使用私钥解密AES密钥,并使用检索到的密钥解密数据.然后验证MAC(如果您将其包括在协议中).最后解密密文以检索明文.

The server can now decrypt the AES keys using the private key and decrypt the data with the retrieved keys. Then verify the MAC, if you included it in your protocol. Finally decrypt the ciphertext to retrieve the plaintext.

此方案称为混合加密,因为它同时使用了对称和非对称加密.如果您不使用MAC,请注意填充oracle攻击(将所有纯文本泄漏给攻击者).解密之前,请务必先验证MAC.

This scheme is called hybrid encryption because it uses both symmetric and asymmetric encryption. Beware of padding oracle attacks (which leak all the plain text to an attacker) if you don't use a MAC. Always verify the MAC before decrypting.

您可以在应用程序中存储RSA公钥.使用此公共密钥,您可以加密AES密钥(使用PKCS#1 OAEP或v1.5填充).

You can store an RSA public key within your application. With this public key you can encrypt an AES key (using PKCS#1 OAEP or v1.5 padding).

这篇关于如何安全存储密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆