pull/1251/head
gedoor 3 years ago
parent 08e4b64d07
commit 66ed414739
  1. 11
      app/src/main/java/io/legado/app/ui/book/login/SourceLoginDialog.kt
  2. 15
      app/src/main/java/io/legado/app/utils/EncoderUtils.kt

@ -2,17 +2,20 @@ package io.legado.app.ui.book.login
import android.os.Bundle import android.os.Bundle
import android.text.InputType import android.text.InputType
import android.util.Base64
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.constant.AppConst
import io.legado.app.data.entities.rule.LoginRule import io.legado.app.data.entities.rule.LoginRule
import io.legado.app.databinding.DialogLoginBinding import io.legado.app.databinding.DialogLoginBinding
import io.legado.app.help.CacheManager import io.legado.app.help.CacheManager
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.text.EditText import io.legado.app.ui.widget.text.EditText
import io.legado.app.ui.widget.text.TextInputLayout import io.legado.app.ui.widget.text.TextInputLayout
import io.legado.app.utils.EncoderUtils
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -63,6 +66,13 @@ class SourceLoginDialog : BaseDialogFragment() {
} }
} }
} }
val data = Base64.encodeToString(
EncoderUtils.decryptAES(
GSON.toJson(loginData).toByteArray(),
AppConst.androidId.toByteArray()
),
Base64.DEFAULT
)
CacheManager.put("login_$sourceUrl", GSON.toJson(loginData)) CacheManager.put("login_$sourceUrl", GSON.toJson(loginData))
} }
} }
@ -70,5 +80,4 @@ class SourceLoginDialog : BaseDialogFragment() {
} }
} }
} }

@ -92,8 +92,8 @@ object EncoderUtils {
fun decryptBase64AES( fun decryptBase64AES(
data: ByteArray?, data: ByteArray?,
key: ByteArray?, key: ByteArray?,
transformation: String?, transformation: String = "DES/CBC/PKCS5Padding",
iv: ByteArray? iv: ByteArray? = null
): ByteArray? { ): ByteArray? {
return decryptAES(Base64.decode(data, Base64.NO_WRAP), key, transformation, iv) return decryptAES(Base64.decode(data, Base64.NO_WRAP), key, transformation, iv)
} }
@ -111,10 +111,10 @@ object EncoderUtils {
fun decryptAES( fun decryptAES(
data: ByteArray?, data: ByteArray?,
key: ByteArray?, key: ByteArray?,
transformation: String?, transformation: String = "DES/CBC/PKCS5Padding",
iv: ByteArray? iv: ByteArray? = null
): ByteArray? { ): ByteArray? {
return symmetricTemplate(data, key, "AES", transformation!!, iv, false) return symmetricTemplate(data, key, "AES", transformation, iv, false)
} }
@ -128,7 +128,7 @@ object EncoderUtils {
* @param isEncrypt True to encrypt, false otherwise. * @param isEncrypt True to encrypt, false otherwise.
* @return the bytes of symmetric encryption or decryption * @return the bytes of symmetric encryption or decryption
*/ */
@Suppress("SameParameterValue")
private fun symmetricTemplate( private fun symmetricTemplate(
data: ByteArray?, data: ByteArray?,
key: ByteArray?, key: ByteArray?,
@ -137,7 +137,8 @@ object EncoderUtils {
iv: ByteArray?, iv: ByteArray?,
isEncrypt: Boolean isEncrypt: Boolean
): ByteArray? { ): ByteArray? {
return if (data == null || data.isEmpty() || key == null || key.isEmpty()) null else try { return if (data == null || data.isEmpty() || key == null || key.isEmpty()) null
else try {
val keySpec = SecretKeySpec(key, algorithm) val keySpec = SecretKeySpec(key, algorithm)
val cipher = Cipher.getInstance(transformation) val cipher = Cipher.getInstance(transformation)
if (iv == null || iv.isEmpty()) { if (iv == null || iv.isEmpty()) {

Loading…
Cancel
Save