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.
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).
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.
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.
Is var myClientSecret = Encoding.UTF8.GetBytes("MySuperSecretClientSecretKey")
the only alternative?
Does the framework provide anything helping me accomplish this task?