Android:在我的Java代码中放入敏感字符串是否安全?

Sco*_*ott 9 java encryption android proguard code-access-security

我的应用程序使用了许多我无法让用户看到的API密钥和URL.我一直把它们直接放在代码中,有时嵌入在使用它们的方法中,有时在一个名为MyVals的类中,它存储常用的字符串和数字.

例如:

public class MyVals {

    private LGVals(){}

    public static final String DB_URL = "https://mydb.dbprovider.org/";
    public static final String DB_Key = "klJF*(oh8iyhkkde";
    public static final String TableKey_UserList = "o9w6owifhayf98fnwihj";

}
Run Code Online (Sandbox Code Playgroud)

这样安全吗?如果我用Proguard创建我的APK会有所不同吗?这是最好的做法是什么?

AWT*_*AWT 5

这绝对不是安全的敏感字符串嵌入到你的代码.Proguard模糊了类和方法名称,但任何已定义的字符串都保持完全不变.这是我通过Proguard运行的应用程序的示例.您可以看到方法和类名称被混淆,但字符串(必须是)保持不变.

这是原始代码:

public void shutdown() {
    if (logger.logDebug()) {
        logger.logDebug(LOGTAG, "Queuing shutdown message ...");
    }

    queueMessage(new BaseMessage(true));
}
Run Code Online (Sandbox Code Playgroud)

以及由JD-GUI轻松获得的混淆代码:

  public void c()
  {
    if (c.logDebug())
      c.logDebug("MsgRouter", "Queuing shutdown message ...");
    a(new a(true));
  }
Run Code Online (Sandbox Code Playgroud)

如果您在应用程序的字符串中嵌入敏感数据,则可以并将对其进行反编译.

  • 那我们该怎么办?! (3认同)