优化
This commit is contained in:
@@ -8,6 +8,7 @@ import io.legado.app.constant.AppLog
|
|||||||
import io.legado.app.data.entities.rule.RowUi
|
import io.legado.app.data.entities.rule.RowUi
|
||||||
import io.legado.app.help.CacheManager
|
import io.legado.app.help.CacheManager
|
||||||
import io.legado.app.help.JsExtensions
|
import io.legado.app.help.JsExtensions
|
||||||
|
import io.legado.app.help.SymmetricCryptoAndroid
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.help.http.CookieStore
|
import io.legado.app.help.http.CookieStore
|
||||||
import io.legado.app.model.SharedJsScope
|
import io.legado.app.model.SharedJsScope
|
||||||
@@ -106,6 +107,7 @@ interface BaseSource : JsExtensions {
|
|||||||
it.lastIndexOf("<")
|
it.lastIndexOf("<")
|
||||||
)
|
)
|
||||||
).toString()
|
).toString()
|
||||||
|
|
||||||
else -> it
|
else -> it
|
||||||
}
|
}
|
||||||
).getOrNull()?.let { map ->
|
).getOrNull()?.let { map ->
|
||||||
@@ -176,7 +178,7 @@ interface BaseSource : JsExtensions {
|
|||||||
fun putLoginInfo(info: String): Boolean {
|
fun putLoginInfo(info: String): Boolean {
|
||||||
return try {
|
return try {
|
||||||
val key = (AppConst.androidId).encodeToByteArray(0, 16)
|
val key = (AppConst.androidId).encodeToByteArray(0, 16)
|
||||||
val encodeStr = AES(key).encryptBase64(info)
|
val encodeStr = SymmetricCryptoAndroid("AES", key).encryptBase64(info)
|
||||||
CacheManager.put("userInfo_${getKey()}", encodeStr)
|
CacheManager.put("userInfo_${getKey()}", encodeStr)
|
||||||
true
|
true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ interface JsEncodeUtils {
|
|||||||
key: ByteArray?,
|
key: ByteArray?,
|
||||||
iv: ByteArray?
|
iv: ByteArray?
|
||||||
): SymmetricCrypto {
|
): SymmetricCrypto {
|
||||||
val symmetricCrypto = SymmetricCrypto(transformation, key)
|
val symmetricCrypto = SymmetricCryptoAndroid(transformation, key)
|
||||||
return if (iv != null && iv.isNotEmpty()) symmetricCrypto.setIv(iv) else symmetricCrypto
|
return if (iv != null && iv.isNotEmpty()) symmetricCrypto.setIv(iv) else symmetricCrypto
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package io.legado.app.help
|
||||||
|
|
||||||
|
import cn.hutool.crypto.symmetric.SymmetricCrypto
|
||||||
|
import io.legado.app.utils.EncoderUtils
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.nio.charset.Charset
|
||||||
|
|
||||||
|
class SymmetricCryptoAndroid(
|
||||||
|
algorithm: String,
|
||||||
|
key: ByteArray?,
|
||||||
|
) : SymmetricCrypto(algorithm, key) {
|
||||||
|
|
||||||
|
override fun encryptBase64(data: ByteArray): String {
|
||||||
|
return EncoderUtils.base64Encode(encrypt(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun encryptBase64(data: String, charset: String?): String {
|
||||||
|
return EncoderUtils.base64Encode(encrypt(data, charset))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun encryptBase64(data: String, charset: Charset?): String {
|
||||||
|
return EncoderUtils.base64Encode(encrypt(data, charset))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun encryptBase64(data: String): String {
|
||||||
|
return EncoderUtils.base64Encode(encrypt(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun encryptBase64(data: InputStream): String {
|
||||||
|
return EncoderUtils.base64Encode(encrypt(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -37,6 +37,11 @@ object EncoderUtils {
|
|||||||
fun base64Encode(str: String, flags: Int = Base64.NO_WRAP): String? {
|
fun base64Encode(str: String, flags: Int = Base64.NO_WRAP): String? {
|
||||||
return Base64.encodeToString(str.toByteArray(), flags)
|
return Base64.encodeToString(str.toByteArray(), flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmOverloads
|
||||||
|
fun base64Encode(bytes: ByteArray, flags: Int = Base64.NO_WRAP): String {
|
||||||
|
return Base64.encodeToString(bytes, flags)
|
||||||
|
}
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun base64DecodeToByteArray(str: String, flags: Int = Base64.DEFAULT): ByteArray {
|
fun base64DecodeToByteArray(str: String, flags: Int = Base64.DEFAULT): ByteArray {
|
||||||
|
|||||||
Reference in New Issue
Block a user