如何在我的应用程序中存储机密?

如何在我的应用程序中存储机密?

问题描述:

我在回答此处的一个问题,建议使用.NET的密码库(例如

I was answering a question here suggesting the usage of .NET's cryptographic libraries (e.g. AesManaged) when I wondered: "but where the key used by the application should be placed?".

我有一个秘密,需要存储在应用程序内部,该应用程序应使用该应用程序,但用户不知道,我不知道知道该怎么做。

I have a secret I need to store inside my application which should be used by the application but not known by the user, and I don't know how to do it.

我所谈论的秘密不是与用户相关的(例如,用户向第三方服务提供的密码),而是某些应用程序-或用户不应该知道的与开发人员相关的信息(例如,如果用户知道应用程序的OAuth客户端机密,则可以模仿第三方服务来模仿开发人员)。

The kind of secret I'm talking about is not something user-related (e.g. a user's password to a third party service) but womething application- or developer-related which should not be known by the user (e.g. if a user knows an application's OAuth client secret he can impersonate the developer against the third-party service).

我知道Window的凭据管理器数据保护API 之类,但是在这种情况下它们无济于事,因为它们旨在保护用户的秘密,而且其中大多数是运行时解决方案,而我需要保护的是

I know of Window's Credential Manager, Data Protection API and such, but they don't help in this scenario because they're meant to protect users' secrets, moreover most of them are run-time solutions while what I need to protect is "constant" and "compile-time".

我完全知道,我将采取的任何行动只会延迟熟练且确定的用户访问机密,因为如果应用程序也必须以某种方式以用户可以其纯文本格式对其进行访问。我要寻找的是防止临时用户在记事本中打开应用程序并获取秘密。

I'm fully aware any kind of action I will take will only delay a skilled and detemined user in accessing the secret since if the application must have access to it in its plaintext form the user too can, somehow. What I'm looking for is to prevent casual users from opening the application "in Notepad" and getting the secret.

我完全知道,任何一种措施都可以只是暂时阻止熟练且坚定的用户访问此类秘密,我并没有要求该问题的防弹解决方案,我对除了编写 var myClientSecret = MySuperSecretClientSecretKey之外的其他选择感兴趣; 存储此类信息。

I'm fully aware that any kind of measure is only temporarily stopping a skilled and determined user from accessing such secret, I'm not asking for a bullet proof solution to the problem, I'm interested in which choices I have besides writing var myClientSecret = "MySuperSecretClientSecretKey"; to store such information.

var myClientSecret = Encoding.UTF8.GetBytes( MySuperSecretClientSecretKey)唯一的选择?

框架是否提供任何帮助我完成此任务的东西?

Does the framework provide anything helping me accomplish this task?

将机密存储在智能卡中。购买软件时向用户发送智能卡。

Store the secret in a smart card. Send the user the smart card when they buy the software.

无法读取或克隆存储在智能卡中的密钥。

A key stored in a smart card cannot be read or cloned.