简体   繁体   English

带HSM的对称加密密钥

[英]Symmetric encryption keys with HSM

I want to use an HSM to encrypt/decrypt sensitive data I will be storing in my database. 我想使用HSM加密/解密将存储在数据库中的敏感数据。 The HSM device / server can create symmetric and asymmetric keys. HSM设备/服务器可以创建对称和非对称密钥。 I want to store data with highest possible security. 我想以最高的安全性存储数据。 So I have two approaches: 所以我有两种方法:

1) Make HSM generate a public/private key pair and it will keep the private key inside it and it will never leave. 1)使HSM生成公钥/私钥对,并将其保留在私钥对中,并且永远不会离开。 Now I can create a random symmetric key per entry I want to encrypt. 现在,我可以为每个要加密的条目创建一个随机对称密钥。 I encrypt the data with random AES key, encrypt the AES key with public key generated in HSM and store result of encrypted data + encrypted key data in each row in DB. 我使用随机AES密钥对数据进行加密,使用HSM中生成的公共密钥对AES密钥进行加密,并将加密数据+加密密钥数据的结果存储在DB的每一行中。 Now everytime I want to access the data, I send encrypted key data to HSM, HSM will decrypt it and send me back the decrypted AES key, I use that to actually decrypt data. 现在,每次我要访问数据时,我都会将加密的密钥数据发送给HSM,HSM将对其进行解密,然后将解密后的AES密钥发送给我,我实际上使用它来解密数据。

2) Per row/per entry, I make HSM to generate AES key and store the symmetric key token in it. 2)每行/每项,我使HSM生成AES密钥并将对称密钥令牌存储在其中。 I send data in plaintext to it, it sends me back in encrypted form. 我以明文形式发送数据,它以加密形式发送回我。 Everytime I want to access the data, I send encrypted data to HSM and it will decrypt and send it back to me. 每当我想访问数据时,我都会将加密的数据发送到HSM,它将解密并发送回给我。

HSM server will be a professional and fast one like Thales, so it can handle the traffic with good speed (hopefully). HSM服务器将像Thales一样是专业且快速的服务器,因此它可以(希望)以良好的速度处理流量。

The thing with first one is I only have to login as SO (Security Officer) to generate and store my public/private key pair in HSM and from now on, I just have to login as Read only user. 第一个问题是,我只需要以SO(安全员)身份登录即可在HSM中生成并存储我的公钥/私钥对,从现在开始,我只需以只读用户身份登录。 But its slower and lenghty process compared to number 2. 但与数字2相比,它的流程慢且冗长。

Number 2 (as far as I know) will require me to have SO access to device whole time. 2号(据我所知)将要求我始终对设备进行SO访问。

What do you suggest? 你有什么建议? Please advise. 请指教。

I'm not sure security advice like this is best suited here, but rather than splitting hairs I'll give some advice. 我不确定像这样的安全建议是否最适合这里,但我会给出一些建议,而不是分开讨论。

First of all, I like hybrid (RSA + AES) encryption better because you don't have to protect the public key to encrypt (as long as an attacker cannot replace it with their own public key) - and you may not need to provide a PIN. 首先,我更喜欢混合(RSA + AES)加密,因为您不必保护要加密的公钥(只要攻击者无法用自己的公钥替换它),并且您可能不需要提供PIN码。 So this would give advantage to the first scheme. 因此,这将有利于第一种方案。

To be very secure you would do better to wrap a AES data key instead of encrypting it. 为了非常安全,您最好包装 AES数据密钥而不是对其进行加密。 Wrapping and encrypting are basically the same thing, but after unwrapping the AES key becomes a HSM static or session key , still within the HSM where you can decrypt with it. 打包和加密基本上是相同的,但是解包后,AES密钥变成了HSM静态或会话密钥 ,仍然在HSM内,可以用它进行解密。 Decrypting will return it into insecure memory of the PC. 解密会将其返回到PC的不安全存储器中。 Decrypting on the PC is probably faster but decryption on the HSM is more secure and should be preferred. 在PC上解密可能更快,但在HSM上解密更安全,因此应首选。

You should normally only require SO access for admin tasks. 通常,您只需要对管理任务具有SO访问权限。 Usually you should be able to create objects such as keys using user access. 通常,您应该能够使用用户访问权限来创建诸如键之类的对象。 But in the end those kind of things depend on the HSM configuration. 但是最终,这类事情取决于HSM配置。

Depending on the security settings, a Thales HSM will only create a public/private key pair when the device is Authenticated. 根据安全设置,Thales HSM仅在设备通过身份验证后才会创建公钥/私钥对。 This means you may not be able to create them as you need them. 这意味着您可能无法根据需要创建它们。

A technique I have used is to pre-generated ~1000 public/private key pairs and store this in a keystore (database or otherwise) when the HSM is Authenticated. 我使用的一种技术是预先生成约1000个公用/专用密钥对,并在HSM进行身份验证时将其存储在密钥库(数据库或其他方式)中。 Then you can use a randomly selected key from the database without the HSM being Authenticated. 然后,您可以使用从数据库中随机选择的密钥,而无需验证HSM。

Note the HSM can typically only store 20 keys internally - which is why you may want to store them externally. 注意,HSM通常只能在内部存储20个密钥-这就是为什么您可能想在外部存储它们。 This also works well if you have multiple HSMs that are load balanced. 如果您有多个负载均衡的HSM,这也很好用。

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

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