From 66ed414739d0410f1b2ed5b1531c542c32306b5d Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 18 Aug 2021 14:57:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/login/SourceLoginDialog.kt | 11 ++++++++++- .../main/java/io/legado/app/utils/EncoderUtils.kt | 15 ++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/login/SourceLoginDialog.kt b/app/src/main/java/io/legado/app/ui/book/login/SourceLoginDialog.kt index c75060bff..83713991a 100644 --- a/app/src/main/java/io/legado/app/ui/book/login/SourceLoginDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/login/SourceLoginDialog.kt @@ -2,17 +2,20 @@ package io.legado.app.ui.book.login import android.os.Bundle import android.text.InputType +import android.util.Base64 import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import io.legado.app.R import io.legado.app.base.BaseDialogFragment +import io.legado.app.constant.AppConst import io.legado.app.data.entities.rule.LoginRule import io.legado.app.databinding.DialogLoginBinding import io.legado.app.help.CacheManager import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.text.EditText 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.applyTint 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)) } } @@ -70,5 +80,4 @@ class SourceLoginDialog : BaseDialogFragment() { } } - } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/EncoderUtils.kt b/app/src/main/java/io/legado/app/utils/EncoderUtils.kt index aafdb0d98..504d4a9c1 100644 --- a/app/src/main/java/io/legado/app/utils/EncoderUtils.kt +++ b/app/src/main/java/io/legado/app/utils/EncoderUtils.kt @@ -92,8 +92,8 @@ object EncoderUtils { fun decryptBase64AES( data: ByteArray?, key: ByteArray?, - transformation: String?, - iv: ByteArray? + transformation: String = "DES/CBC/PKCS5Padding", + iv: ByteArray? = null ): ByteArray? { return decryptAES(Base64.decode(data, Base64.NO_WRAP), key, transformation, iv) } @@ -111,10 +111,10 @@ object EncoderUtils { fun decryptAES( data: ByteArray?, key: ByteArray?, - transformation: String?, - iv: ByteArray? + transformation: String = "DES/CBC/PKCS5Padding", + iv: ByteArray? = null ): 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. * @return the bytes of symmetric encryption or decryption */ - + @Suppress("SameParameterValue") private fun symmetricTemplate( data: ByteArray?, key: ByteArray?, @@ -137,7 +137,8 @@ object EncoderUtils { iv: ByteArray?, isEncrypt: Boolean ): 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 cipher = Cipher.getInstance(transformation) if (iv == null || iv.isEmpty()) {