|
|
@ -3,6 +3,7 @@ package io.legado.app.help |
|
|
|
import android.net.Uri |
|
|
|
import android.net.Uri |
|
|
|
import android.util.Base64 |
|
|
|
import android.util.Base64 |
|
|
|
import androidx.annotation.Keep |
|
|
|
import androidx.annotation.Keep |
|
|
|
|
|
|
|
import cn.hutool.crypto.digest.DigestUtil |
|
|
|
import cn.hutool.crypto.symmetric.AES |
|
|
|
import cn.hutool.crypto.symmetric.AES |
|
|
|
import cn.hutool.crypto.symmetric.DESede |
|
|
|
import cn.hutool.crypto.symmetric.DESede |
|
|
|
import io.legado.app.BuildConfig |
|
|
|
import io.legado.app.BuildConfig |
|
|
@ -760,4 +761,102 @@ interface JsExtensions { |
|
|
|
).decryptStr(data) |
|
|
|
).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) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|