一种可能的解决方案是在应用程序中对数据进行编码,并在运行时使用解码(当您想要使用该数据时)。我还建议使用progaurd使您的应用程序的反编译源代码难以阅读和理解。例如,我在应用程序中放置了一个编码键,然后在我的应用程序中使用解码方法在运行时解码我的密钥:
// "the real string is: "mypassword" ";
//encoded 2 times with an algorithm or you can encode with other algorithms too
public String getClientSecret() {
return Utils.decode(Utils
.decode("Ylhsd1lYTnpkMjl5WkE9PQ=="));
}一个proguarded应用程序的反编译源代码是这样的:
public String c()
{
return com.myrpoject.mypackage.g.h.a(com.myrpoject.mypackage.g.h.a("Ylhsd1lYTnpkMjl5WkE9PQ=="));
}至少它对我来说足够复杂。当我别无选择但在我的应用程序中存储值时,这就是我的方式。当然我们都知道这不是最好的方式,但它对我有用。
/**
* @param input
* @return decoded string
*/
public static String decode(String input) {
// Receiving side
String text = "";
try {
byte[] data = Decoder.decode(input);
text = new String(data, "UTF-8");
return text;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "Error";
}反编译版本:
public static String a(String paramString)
{
try
{
str = new String(a.a(paramString), "UTF-8");
return str;
}
catch (UnsupportedEncodingException localUnsupportedEncodingException)
{
while (true)
{
localUnsupportedEncodingException.printStackTrace();
String str = "Error";
}
}
}你可以在谷歌搜索一下这么多的加密类。