android 私有存储,在Android中存储私有API密钥的最佳实践

一种可能的解决方案是在应用程序中对数据进行编码,并在运行时使用解码(当您想要使用该数据时)。我还建议使用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";

}

}

}你可以在谷歌搜索一下这么多的加密类。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值