.Net Encryption

前端 未结 4 1193
忘了有多久
忘了有多久 2020-12-07 23:11

What I would like to know is the definite approach to encrypting connection strings in a config file. Here are my questions:

  1. Using machine-level encryption,

相关标签:
4条回答
  • 2020-12-07 23:54

    Storing secrets with a symmetric encryption is always problematic as long as you do not want to promt for a password or use another technical solution to decrypt your secret (like special hardware). When you have to store the complete key anywhere on the system there will be a way for other people to retrieve it.

    I would definitely try to use the operating system's mechanism. When you work in a pure windows environment with MS-SQL you should use the integrated security instead of user/password. Other databases might have similar capabilities, too.
    Another (weaker) option is to secure the cleartext file with the security settings of the operating system - only the user gets access to the file. However you and your users have to trust the administrators. In this case you should use symmetric encryption in addition. But see my first arguments - it will not be really secure.

    0 讨论(0)
  • 2020-12-07 23:58
    1. Yes. Secrets encrypted with the machine key can be decrypted by any process with access to the machine key. Secrets encrypted with the user key can be decrypted by any process started by the same user.
    2. This is not possible. All contrary claims are snake oil. You application needs a secret to decrypt something. There are no known schemes to hide a secret inside an application. There are various obfuscation schemes, but nothing bulletproof. The best you can do is to raise the bar.
    3. No. Either the application has the secret key to decrypt something, in which case you go back to point 2, or your application has the public key, in which case anyone can decrypt the same secret, so you basically do a validation of the configuration (was not tampered with), but the configuration is not secret.
    4. You cannot deploy embedded secrets in an application securely. Is just a matter of how high is the price, if your protected asset (the secret) is worth it, then a hacker will get it.

    The encryption infrastructure is designed to protect the secrets of the current user from other users. It is not designed to protect the secrets of an application from the user using it. What you ask for is not encryption, is DRM, and you need to look into the DRM infrastructure for answers. I'm not aware of a managed library around the DRM API.

    0 讨论(0)
  • 2020-12-07 23:58

    Gustavo you may be able to implement this, (this is my plan for my application which is login based).

    User inputs credentials in .Net app. Credentials get passed over to a .php server-side application which uses them to log in to the database and retrieve a key and pass it back to the .Net app. The key is then used on the hardcoded encrypted connection strings in the .Net app to allow full database access.

    0 讨论(0)
  • 2020-12-08 00:01

    Good question actually,

    You can not be sure noone will decrypt your connection string (or password). Of course you can encrypt it, but people will be able to decompile your application and see what encryption algrorithm you use and what key you use to decrypt your connection string/password. Maybe it's more like extreme scenario but it is possible (I was an evil cracker in student years :) ). So if you are afraid of such a scenario you have to protect your application, make it harder to disassemble. It's a theme for another discussion, but for example you can use Dotfuscator or other good obfuscator - it will make it harder for a cracker to understand what is going on inside your application.
    So, one possible solution can be "encrypt connection string + use obfuscator", but, as I said, it will not give you 100% protection.

    0 讨论(0)
提交回复
热议问题