gpt4 book ai didi

android webview加密内容

转载 作者:太空狗 更新时间:2023-10-29 15:19:53 39 4
gpt4 key购买 nike

我有一个使用 webview 来显示内容的应用程序,Javascript 调用是我的应用程序的 Controller 。为了提供一定程度的安全性,我混淆了代码。这还不够,因为我想加密 html 和 js 文件,然后在运行时解密它们。我用这些用RC4算法加密的资源打包了apk文件。加载文件时,我正在解密 javascript 文件,加载它们,然后解密 html 文件并加载它。然而,这不起作用,因为 webcontent 以以下形式显示消息:位于 data:text/html 的网页可能暂时关闭或可能已永久移动,等等。我重载了 onLoadResource 以查看加载了哪些内容,我可以看到它加载了 Javascript 内容,但加载的内容也是 html 转义的。

我的问题是:1. 如何保护 html 和 javascript 文件(位于 assets 文件夹中)以使其无法访问?2. 如果我的方法是正确的,有人知道我做错了什么吗?

谢谢!

下面是解密和加载资源的代码:

protected void loadWebContent() {
checkEncryptionEnabled();
loadJSFiles();
logger.info("Loaded js ... going for html");
loadAssetFile("www/index.html", "text/html");
}

private void loadJSFiles() {
String[] jsFilesArray = { "app.js", "iscroll.js", "iui.js", "json.js" };
for (String js : jsFilesArray) {
loadAssetFile("www/js/" + js, "application/javascript");
}
}

private void loadAssetFile(String filePath, String mimeType) {
AssetManager assetMgr = getAssets();
InputStream is = null;
try {
is = assetMgr.open(filePath);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] temp = new byte[512];
int bytesRead = -1;
while ((bytesRead = is.read(temp)) > 0) {
baos.write(temp, 0, bytesRead);
}
byte[] encrypted = baos.toByteArray();
String content = null;
/**
* true
* */
if (Config.ENCRYPTION_ENABLED) {
byte[] decrypted = new RC4Encrypter("rc4_key").rc4(encrypted);
content = new String(decrypted, "utf-8");
} else {
content = new String(encrypted, "utf-8");
}

/**
* The webview to use
* */
if("application/javascript".equals(mimeType)) {
webContent.loadUrl("javascript:" + content);
} else {
webContent.loadData(content, mimeType, "utf-8");
}
} catch (IOException ex) {
logger.error(null, ex);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
}

最佳答案

找到第二个问题的答案而不是:webContent.loadData(content, mimeType, "utf-8"); 我用的是:webContent.loadDataWithBaseURL("file:///android_asset/www/", content, mimeType, "utf-8", null); 内容显示没有问题......但是,第一个问题有点站不住脚;但考虑到一年多都没有得到答复,我认为加密数据是可以的。

关于android webview加密内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8971760/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com