SecureString如何“加密”还可以用吗 [英] How is SecureString "encrypted" and still usable?

查看:170
本文介绍了SecureString如何“加密”还可以用吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据MSDN SecureString 内容已加密为了额外的安全,所以如果程序被交换到磁盘,字符串内容不能被嗅探。



如何加密可能我想知道?该算法将是固定的,因此是众所周知的或可以扣除的(例如在业界算法中广泛使用的七种之一),并且程序中的某处必须有一个关键点。所以攻击者可以获取加密的字符串,获取密钥并解密数据。



这种加密如何有用?

解决方案

我引用了一篇关于 DPAPI 。这应该回答你对SecureString的大多数问题。



是的,SecureString有缺点,并不完全安全,有办法访问数据,例如注入在MSDN上提到 Hawkeye ,以提取SecureString。我没有亲自验证这个说法。



DAPI密钥管理




DAPI是一种基于对称的加密技术,它使用相同的密钥来加密和解密数据。在了解如何使用DAPI的一些示例之前,值得介绍DAPI如何管理其密钥。在大多数情况下,DAPI密钥管理过程是无阻碍的,您通常不需要担心,这是DAPI是一个很好的方法的主要原因。



介绍我写的主密钥是从用户的登录密码生成的。这不是完整的图片。实际发生的是Windows使用用户的登录密码来生成主密钥。该主密钥使用用户密码进行保护,然后与用户的配置文件一起存储。然后,该主密钥被用于导出许多其他密钥,这是用于保护数据的其他密钥。



Windows执行此操作的原因是允许应用程序将附加信息(称为熵)添加到生成个人密钥的过程中。您看到运行在用户登录帐户下的每个应用程序是否使用相同的密钥,那么每个应用程序都可以取消保护DAPI保护的数据。有时您可能希望应用程序能够共享DAPI保护的数据;然而,有时你不会。通过使应用程序为生成密钥提供熵,那么该密钥将成为应用程序特定的,并且如果知道该熵值,则该应用程序所保护的任何数据只能再次被保护。



虽然生成一个主密钥,然后使用该主密钥生成其他密钥来进行实际加密,但似乎是一个长期的方法,它有一个主要优点。由于用户密码保护主密钥和用于保护数据的实际密钥之间存在额外的抽象级别,这意味着当用户更改密码时,只需要重新保护主密钥;没有一个受保护的数据需要被重新保护。由于主密钥的大小远小于数据,因此可以显着节省性能。



当用户的密码更改时,当然会生成一个新的主密钥。然后使用这个新的主密钥来生成新的单独的密钥。然而,由于以前生成的所有单个密钥都是从旧的主密钥导出的,所以Windows需要存储所有之前的主密钥。 Windows从不忘记主密钥,所有受保护的数据都标有GUID,该GUID指示用于保护数据的主密钥。因此,在适应性方面,DAPI能够应对用户密码的变化,同时确保a)受保护的数据不需要重新保护,以及b)用于先前保护数据的密钥仍然可用,c )它自动为您做所有这些。



除非计算机是域的成员,否则DAPI只能在用于保护它的同一台计算机上的不受保护的数据。 / p>

除了允许用户级别保护,在主密钥是基于用户密码的情况下,一个用户的受保护数据不能被其他用户不受保护,DAPI还提供机器级保护因为主密钥是基于机器特定的信息。机器级主密钥允许应用程序存储受保护的数据,以便该应用程序的所有用户都可以不受保护。已经描述的过程的唯一区别是主机是从机器特定信息而不是用户特定的信息生成的。



According to MSDN SecureString contents is encrypted for additional safety so that if the program is swapped to disk the string contents can't be sniffed.

How is such encryption possible I wonder? The algorithm would be fixed and therefore either well-known or deductible (say one of seven widely used in industry algorithms) and there must be a key somewhere in the program. So the attacker could fetch the encrypted string, fetch the key and decrypt the data.

How can such encryption be useful?

解决方案

I'm quoting from an article about the DPAPI which is used to derive the key. This should answer most questions that you have about SecureString.

And yes, SecureString has drawbacks and is not completely secure, there are ways to access to data, for example, injecting Hawkeye into the process is mentioned on MSDN as a way to extract the SecureString. I have not personally verifed this assertation.

DAPI Key Management

DAPI is a symmetric based encryption technique, which means it uses the same key to both encrypt and decrypt data. Before getting to some examples of how to use DAPI it's worth covering how DAPI manages its key. For the most part DAPI key management process is invisble and you generally don't need to worry about it, which is the main reason why DAPI is a good approach.

In the introduction I wrote that the master key is generated from the user's login password. This isn't the complete picture. What actually happens is Windows uses the user's login password to generate a master key. This master key is protected using the user's password and then stored along with the user's profile. This master key then gets used to derive a number of other keys and it's these other keys that are used to protect the data.

The reason why Windows does this is it allows applications to add additional information, called entropy, to the process of generating the individul keys. You see if every application running under the user's login account used the same key then every application could unprotect DAPI protected data. Sometimes you might want applications to be able to share DAPI protected data; however, sometimes you won't. By letting the application contribute entropy to the generation of a key then that key becomes application specific and any data that is protected by that application can only be unprotected again if they know the entropy.

Although generating a master key, and then using that master key to generate other keys to do the actual encryption, might seem like a long winded approach it does have one major advantage. Since there is an additional level of abstraction between the user password protected master key and the actual keys used to protect the data it means that when the user changes their password then only the master key need to be re-protected; none of the protected data needs to be re-protected. Since the master key is much smaller in size than the data then a significant performance saving is made.

When the user's password changes then of course a new master key is generated. This new master key is then used to generate new individual keys. However, since all the previously generated individual keys were derived from the old master key then Windows needs to store all previous master keys, which it does. Windows never forgets a master key and all protected data is marked with a GUID that indicates which master key was used to protect the data. So in terms of adaptability DAPI is able to cope with changes to users' passwords, while ensuring a) that protected data doesn't need to be re-protected, and b) that keys used to previously protect data as still available, and c) it does all this automatically for you.

Unless the computer is a member of a domain DAPI can only unprotected data on the same machine that was used to protect it.

As well as allowing user level protection, in that master keys are based on user passwords and protected data for one user cannot be unprotected by another user, DAPI also provides machine level protection, in that the master keys are based on machine specific information. Machine level master keys allow applications to store protected data so that it can be unprotected by all users of the application. The only difference in the process already described is the master key is generated from machine specific information not user specific information.

这篇关于SecureString如何“加密”还可以用吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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