11

My application makes use of the RijndaelManaged class to encrypt data. As a part of this encryption, I use a SecureString object loaded with a password which get's get converted to a byte array and loaded into the RajindaelManaged object's Key at runtime.

The question I have is the storage of this SecureString. A user entered password can be entered at run-time, and that can be "securely" loaded into a SecureString object, but if no user entered password is given, then I need to default to something.

So ultimately the quesiton comes down to:

If I have to have some known string or byte array to load into a SecureString object each time my application runs, how do I do that? The "encrypted" data ultimately gets decrypted by another application, so even if no user entered password is specified, I still need the data to be encrypted while it goes from one app to another. This means I can't have the default password be random, because the other app wouldn't be able to properly decrypt it.

One possible solution I'm thinking is to create a dll which only spits out a single passphrase, then I use that passphrase and run it through a couple of different hashing/reorganizing functions at runtime before I ultimately feed it into the secureString object. Would this be secure enough?

Edit For clarity*: The encrypted data is being passed via files between machines. Think of it as a Zip file which always has a password, a default one is assumed if nothing is directly entered by the user.

4

5 回答 5

8

There is no point in symmetrically encrypting with a string that's hard-coded into your executable. It will only give a false sense of security. No amount of hashing fixes this scheme.

See this Pidgin FAQ for the same point in a different context.

I am unclear why you think you need the inter-app communication to be encrypted. If this communication is local to the machine, then I don't see the need for encryption, particularly encryption that isn't user-specific. Is this a DRM scheme?

EDIT: If it's being passed to a different machine, perhaps you can hard-code a public key, and then have the other machine decrypt with the matching private key.

于 2010-06-14T22:17:14.397 回答
6

埃里克·利珀特的《你想加盐吗?原博文

另请阅读他的帖子,以使用正确的工具完成工作,最后他给出了以下提示:

  1. 如果可以的话,干脆不要去那里。加密非常难以正确处理,而且通常首先是错误的解决方案。使用其他技术来解决您的安全问题。

  2. 如果问题是不可信的客户端,那么不要构建需要信任客户端的安全解决方案。

  3. 如果您可以使用现成的零件,那么就这样做。

  4. 如果您不能使用现成的零件并且必须使用密码系统,那么请不要使用您不完全理解的密码系统。

  5. 如果你必须使用一个你不完全理解的密码系统,那么至少不要用它来解决它没有被设计用来解决的问题。

  6. 如果您必须使用密码系统来穿越树木,那么至少不要让可能是敌对的客户端选择加密的消息。自己选择令牌。如果令牌必须包含来自客户端的信息,则以某种方式对其进行清理;要求它只是纯 ASCII 文本,插入随机空格,等等。

  7. 如果您必须允许客户端选择令牌,则不要加密令牌本身。签署令牌的加密安全哈希。攻击者更难选择产生所需哈希的令牌。

  8. 不要使用与保护传入消息相同的密钥对来加密传出消息。为您要执行的每个逻辑上不同的操作获取一个密钥对。

  9. 双向加密通信。

  10. 考虑有一个吊销机制,这样一旦你知道夏娃在攻击你,你至少可以吊销她的执照。(或者您可以撤销已知被泄露的许可证,等等。)

于 2010-06-14T23:19:53.583 回答
6

让我先解决你的最后一个问题。

“这样够安全吗?”

唯一能回答的就是你。这里没有人知道在您的应用程序上下文中“足够安全”是什么意思。

您是否正在构建一个应用程序来记录少女的日记?当然,它会“足够安全”。

您是否正在构建应用程序来为军用级安全系统加密信息或身份验证?不,甚至没有接近。

如果您打算将密码存储在源代码中并因此可执行,则只能依靠一种安全性,那就是安全性 obscurity

如果您的问题是您不能或不会将密码存储在源代码中,然后将其移动到单独的 dll 中不会解决任何问题,那么您只是将问题移动到了另一个项目。

但是,我想知道一些事情。你说“我必须默认某些东西”。是这样吗?您正在尝试在源代码中存储安全密码字符串的默认值?“THISISNOTAPASSWORD”怎么样?

于 2010-06-14T22:23:38.257 回答
2

在我看来,也许您应该使用 PKI 解决方案而不是加密/解密。如果您有另一个应用程序需要使用加密数据,那么您可以拥有该应用程序的密钥对,并将公钥提供给正在执行加密的应用程序。这样,您仍然可以保证数据的安全,但不会引入一堆最终无法提供太多保护的附加代码。

一个快速的谷歌搜索给了我这篇代码项目文章,它讨论了在 .Net 中使用 Windows 证书存储

于 2010-06-14T22:23:39.460 回答
2

这篇关于保护 SQL 连接字符串的文章应该同样适用于存储加密密码,您可以让操作系统为您的解密处理加盐种子的加密。

于 2010-06-14T22:23:09.407 回答