在 Java 源代码中隐藏密码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12193981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 07:58:47  来源:igfitidea点击:

Hide password in Java source code

javasecurityproguard

提问by Howard

I need to hide the password in the source, what are the possible methods to obfuscate the password in order to reduce the risk of decompilation?

我需要在源码中隐藏密码,有哪些方法可以混淆密码以降低反编译的风险?

e.g.

例如

final String password = "secret";

回答by Michael Borgwardt

Don't bother.

不要打扰。

Your average user won't be able or willing to decompile class files anyway, and a motivated and skilled attacker won't be held back by obfuscation when the target is a single piece of data. All it takes is one such motivated and skilled attacker and the whole world knows the password.

无论如何,您的普通用户将无法或不愿意反编译类文件,并且当目标是单个数据时,一个有动力且技术娴熟的攻击者不会被混淆所阻碍。只需要一个这样有动力和技术的攻击者,全世界都知道密码。

If your security depends on obfuscating a password, you have already lost.

如果您的安全依赖于混淆密码,那么您已经输了。

回答by Luchian Grigore

First, I wouldn't name my variable password.

首先,我不会命名我的变量password

Second, I wouldn't keep it in raw format, but encode it.

其次,我不会将其保留为原始格式,而是对其进行编码。

Third, I'd use a char[]instead of String(because strings reside in the string pool).

第三,我会使用 achar[]而不是String(因为字符串驻留在字符串池中)。

Of course the best option would be to not keep it in the code at all.

当然,最好的选择是根本不将其保留在代码中。

回答by MadProgrammer

Encrypt the password using an external method, a method that can be used decrypt within your code and store the password (encrypted) on your code

使用外部方法加密密码,该方法可用于在您的代码中解密并将密码(加密)存储在您的代码中

回答by Eduard

Use database or file to save your pasword. Here is pretty good postwith example. But still you need to store somewhere one master password to encrypt your passwords. Tt's hard to protect it from being found and misused to decrypt your passwords :(.

使用数据库或文件来保存您的密码。这是带有示例的非常好的帖子。但是您仍然需要在某处存储一个主密码来加密您的密码。很难保护它不被发现并被滥用来解密您的密码:(。