|
|
|
@ -3,6 +3,7 @@ package io.legado.app.help |
|
|
|
|
import android.net.Uri |
|
|
|
|
import android.util.Base64 |
|
|
|
|
import androidx.annotation.Keep |
|
|
|
|
import cn.hutool.crypto.digest.DigestUtil |
|
|
|
|
import cn.hutool.crypto.symmetric.AES |
|
|
|
|
import cn.hutool.crypto.symmetric.DESede |
|
|
|
|
import io.legado.app.BuildConfig |
|
|
|
@ -134,23 +135,23 @@ interface JsExtensions { |
|
|
|
|
return cacheFile(urlStr, 0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
/** |
|
|
|
|
* 缓存以文本方式保存的文件 如.js .txt等 |
|
|
|
|
* @param urlStr 网络文件的链接 |
|
|
|
|
* @param saveTime 缓存时间,单位:秒 |
|
|
|
|
* @return 返回缓存后的文件内容 |
|
|
|
|
* @param urlStr 网络文件的链接 |
|
|
|
|
* @param saveTime 缓存时间,单位:秒 |
|
|
|
|
* @return 返回缓存后的文件内容 |
|
|
|
|
*/ |
|
|
|
|
fun cacheFile(urlStr: String, saveTime: Int = 0): String? { |
|
|
|
|
val key = md5Encode16(urlStr) |
|
|
|
|
val cache = CacheManager.getFile(key) |
|
|
|
|
if (cache.isNullOrBlank()) { |
|
|
|
|
log("首次下载 $urlStr") |
|
|
|
|
val value = ajax(urlStr) ?: return null |
|
|
|
|
CacheManager.putFile(key, value, saveTime) |
|
|
|
|
return value |
|
|
|
|
} |
|
|
|
|
return cache |
|
|
|
|
} |
|
|
|
|
val key = md5Encode16(urlStr) |
|
|
|
|
val cache = CacheManager.getFile(key) |
|
|
|
|
if (cache.isNullOrBlank()) { |
|
|
|
|
log("首次下载 $urlStr") |
|
|
|
|
val value = ajax(urlStr) ?: return null |
|
|
|
|
CacheManager.putFile(key, value, saveTime) |
|
|
|
|
return value |
|
|
|
|
} |
|
|
|
|
return cache |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
*js实现读取cookie |
|
|
|
@ -760,4 +761,102 @@ interface JsExtensions { |
|
|
|
|
).decryptStr(data) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* AES加密并转为Base64,算法参数经过Base64加密 |
|
|
|
|
* |
|
|
|
|
* @param data 被加密的字符串 |
|
|
|
|
* @param key Base64后的密钥 |
|
|
|
|
* @param mode 模式 |
|
|
|
|
* @param padding 补码方式 |
|
|
|
|
* @param iv Base64后的加盐 |
|
|
|
|
* @return 加密后的Base64 |
|
|
|
|
*/ |
|
|
|
|
fun aesEncodeArgsBase64Str( |
|
|
|
|
data: String, |
|
|
|
|
key: String, |
|
|
|
|
mode: String, |
|
|
|
|
padding: String, |
|
|
|
|
iv: String |
|
|
|
|
): String? { |
|
|
|
|
return AES( |
|
|
|
|
mode, |
|
|
|
|
padding, |
|
|
|
|
Base64.decode(key, Base64.NO_WRAP), |
|
|
|
|
Base64.decode(iv, Base64.NO_WRAP) |
|
|
|
|
).encryptBase64(data) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 3DES加密并转为Base64 |
|
|
|
|
* |
|
|
|
|
* @param data 被加密的字符串 |
|
|
|
|
* @param key 密钥 |
|
|
|
|
* @param mode 模式 |
|
|
|
|
* @param padding 补码方式 |
|
|
|
|
* @param iv 加盐 |
|
|
|
|
* @return 加密后的Base64 |
|
|
|
|
*/ |
|
|
|
|
fun tripleDESEncodeBase64Str( |
|
|
|
|
data: String, |
|
|
|
|
key: String, |
|
|
|
|
mode: String, |
|
|
|
|
padding: String, |
|
|
|
|
iv: String |
|
|
|
|
): String? { |
|
|
|
|
return DESede(mode, padding, key.toByteArray(), iv.toByteArray()).encryptBase64(data) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 3DES加密并转为Base64,算法参数经过Base64加密 |
|
|
|
|
* |
|
|
|
|
* @param data 被加密的字符串 |
|
|
|
|
* @param key Base64后的密钥 |
|
|
|
|
* @param mode 模式 |
|
|
|
|
* @param padding 补码方式 |
|
|
|
|
* @param iv Base64后的加盐 |
|
|
|
|
* @return 加密后的Base64 |
|
|
|
|
*/ |
|
|
|
|
fun tripleDESEncodeArgsBase64Str( |
|
|
|
|
data: String, |
|
|
|
|
key: String, |
|
|
|
|
mode: String, |
|
|
|
|
padding: String, |
|
|
|
|
iv: String |
|
|
|
|
): String? { |
|
|
|
|
return DESede( |
|
|
|
|
mode, |
|
|
|
|
padding, |
|
|
|
|
Base64.decode(key, Base64.NO_WRAP), |
|
|
|
|
Base64.decode(iv, Base64.NO_WRAP) |
|
|
|
|
).encryptBase64(data) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 生成摘要,并转为16进制字符串 |
|
|
|
|
* |
|
|
|
|
* @param data 被摘要数据 |
|
|
|
|
* @param algorithm 签名算法 |
|
|
|
|
* @return 16进制字符串 |
|
|
|
|
*/ |
|
|
|
|
fun digestHex( |
|
|
|
|
data: String, |
|
|
|
|
algorithm: String, |
|
|
|
|
): String? { |
|
|
|
|
return DigestUtil.digester(algorithm).digestHex(data) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 生成摘要,并转为Base64字符串 |
|
|
|
|
* |
|
|
|
|
* @param data 被摘要数据 |
|
|
|
|
* @param algorithm 签名算法 |
|
|
|
|
* @return Base64字符串 |
|
|
|
|
*/ |
|
|
|
|
fun digestBase64Str( |
|
|
|
|
data: String, |
|
|
|
|
algorithm: String, |
|
|
|
|
): String? { |
|
|
|
|
return Base64.encodeToString(DigestUtil.digester(algorithm).digest(data), Base64.NO_WRAP) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|