简体   繁体   English

当应用程序将在多台机器上使用时,在 C# 代码中隐藏密钥(密码)的最佳方法?

[英]Best approach to hide secret key(password) in C# code when application will be used on multiple machines?

To access a API, I have to have a secret key.要访问 API,我必须有一个密钥。 How would you approach storing that secret key, if this is going to be used on multiple machines?如果要在多台机器上使用,您将如何存储该密钥?

I read this answer , and if I understand it correctly, besides some obfuscation, there's no point doing anything more?我阅读了这个答案,如果我理解正确,除了一些混淆之外,再做任何事情都没有意义吗?

It's not easy because IL code is readable.这并不容易,因为 IL 代码是可读的。 And the IL code easily gain from a binary like DLL or EXE using IL Disassembler: ildasm.exe. IL 代码可以使用 IL 反汇编程序从 DLL 或 EXE 等二进制文件中轻松获得:ildasm.exe。

The solution that @miniHessel said, downloading the code from a server using SSL is also not a safety solution, because a client on his/her own machine can track the SSL communication doing a "MITM attack" with a proxy like Fiddler or any other app. @miniHessel 所说的解决方案,使用 SSL 从服务器下载代码也不是一个安全的解决方案,因为他/她自己机器上的客户端可以跟踪 SSL 通信,并使用 Fiddler 或任何其他代理等代理进行“中间人攻击”应用程序。 We have a lot.我们有很多。

We can only make things more difficult: One solution is to encrypt the secret and keep the encrypted secret in the code.我们只能让事情变得更加困难:一种解决方案是对秘密进行加密并将加密后的秘密保存在代码中。 (before you use it you can decrypt it) Better if you cut the encrypted secret to multiple parts and keep it different place in the code. (在您使用它之前,您可以对其进行解密)如果将加密的秘密分成多个部分并将其保留在代码中的不同位置,则效果会更好。 And merge them before you decrypt it.并在解密之前合并它们。 Give the variables and functions innocent name, so noone can figure out what the content is.给变量和函数起无辜的名字,这样没人能弄清楚内容是什么。

A good encryption/decryption solution is here: Encrypting & Decrypting a String in C#一个好的加密/解密解决方案在这里: Encrypting & Decrypting a String in C#

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM