在.NET中加密数据的最佳实践是什么?

时间:2022-01-26 04:03:39

What are the best practices for dealing with

处理的最佳做法是什么?

  1. Things that should be hashed. i.e. passwords
  2. 应该散列的东西。即密码

and

  1. Things that cannot be hashed, but are extremely confidential and would cause tremendous pain if compromised. i.e. credit cards, SSN, missle launch codes.
  2. 那些不能被扼杀的东西,但是非常机密,如果受到损害会造成巨大的痛苦。即信用卡,SSN,导弹发射代码。

Which encryption algorithm is strongest, most recommended? How you do handle the keys?

哪种加密算法最强,最推荐?你是如何处理钥匙的?

2 个解决方案

#1


2  

There are built in crypto libraries you can use in .Net. There are many good symmetric and asymmetric encryption algorithms (AES, RSA, etc) Many of these algorithms let you select how strong a key you want (1024bit, 2048bit, etc).

您可以在.Net中使用内置的加密库。有许多好的对称和非对称加密算法(AES,RSA等)。许多这些算法可以让你选择你想要的密钥强度(1024bit,2048bit等)。

Storing your keys is a much dicier situation. I suggest not in a plain text file. There are algorithms out there for slpitting encryption keys in half so that responsibility is divided.

存储密钥的情况更为严峻。我建议不要在纯文本文件中。有一些算法可以将加密密钥分成两半,以便分担责任。

#2


1  

Regarding hashing, there are built in libraries for performing hash operations (much like the crypto libraries) that make it fairly straightforward to hash a value for storage.

关于散列,有内置的库用于执行散列操作(很像加密库),这使得散列存储值非常简单。

In addition to looking into these libraries, you should also consider adding "salt" to the hashes, which essentially means adding some extra data to the value being hashed prior to the hashing and adds an extra layer of security. In this way even if an attacker knew which hashing algorithm you used they wouldn't easily know how you salted the data before hashing it.

除了查看这些库之外,还应考虑在散列中添加“salt”,这实际上意味着在散列之前向正在散列的值添加一些额外数据,并添加额外的安全层。通过这种方式,即使攻击者知道您使用了哪种哈希算法,他们也不会轻易知道在对数据进行哈希处理之前如何对数据进行盐析。

Another thing to consider would be using the System.Security.SecureString for moving these protected values unencrypted/unhashed around in memory. Using a standard string means that the data being contained in the string is on the heap in plain-text and may actually remain there for a time even after the string goes out of scope. If someone could get a dump of the memory from the machine he/she might able to extract that unprotected data. In some scenarios this might be overkill, but something to look at.

另一件需要考虑的事情是使用System.Security.SecureString在内存中移动未加密/未加密的受保护值。使用标准字符串意味着字符串中包含的数据以纯文本形式存在于堆中,即使在字符串超出范围之后,实际上也可能保留一段时间。如果有人可以从机器中获取内存,他/她可能会提取未受保护的数据。在某些情况下,这可能是过度杀伤,但需要注意的事项。

#1


2  

There are built in crypto libraries you can use in .Net. There are many good symmetric and asymmetric encryption algorithms (AES, RSA, etc) Many of these algorithms let you select how strong a key you want (1024bit, 2048bit, etc).

您可以在.Net中使用内置的加密库。有许多好的对称和非对称加密算法(AES,RSA等)。许多这些算法可以让你选择你想要的密钥强度(1024bit,2048bit等)。

Storing your keys is a much dicier situation. I suggest not in a plain text file. There are algorithms out there for slpitting encryption keys in half so that responsibility is divided.

存储密钥的情况更为严峻。我建议不要在纯文本文件中。有一些算法可以将加密密钥分成两半,以便分担责任。

#2


1  

Regarding hashing, there are built in libraries for performing hash operations (much like the crypto libraries) that make it fairly straightforward to hash a value for storage.

关于散列,有内置的库用于执行散列操作(很像加密库),这使得散列存储值非常简单。

In addition to looking into these libraries, you should also consider adding "salt" to the hashes, which essentially means adding some extra data to the value being hashed prior to the hashing and adds an extra layer of security. In this way even if an attacker knew which hashing algorithm you used they wouldn't easily know how you salted the data before hashing it.

除了查看这些库之外,还应考虑在散列中添加“salt”,这实际上意味着在散列之前向正在散列的值添加一些额外数据,并添加额外的安全层。通过这种方式,即使攻击者知道您使用了哪种哈希算法,他们也不会轻易知道在对数据进行哈希处理之前如何对数据进行盐析。

Another thing to consider would be using the System.Security.SecureString for moving these protected values unencrypted/unhashed around in memory. Using a standard string means that the data being contained in the string is on the heap in plain-text and may actually remain there for a time even after the string goes out of scope. If someone could get a dump of the memory from the machine he/she might able to extract that unprotected data. In some scenarios this might be overkill, but something to look at.

另一件需要考虑的事情是使用System.Security.SecureString在内存中移动未加密/未加密的受保护值。使用标准字符串意味着字符串中包含的数据以纯文本形式存在于堆中,即使在字符串超出范围之后,实际上也可能保留一段时间。如果有人可以从机器中获取内存,他/她可能会提取未受保护的数据。在某些情况下,这可能是过度杀伤,但需要注意的事项。