From bcc2c5b219762088c7941e1acd05dc1dfbbc4db7 Mon Sep 17 00:00:00 2001 From: olixina <695176656@qq.com> Date: Tue, 11 Jan 2022 20:41:37 +0800 Subject: [PATCH] feat: add some decryption methods --- app/build.gradle | 3 + .../java/io/legado/app/help/JsExtensions.kt | 72 +++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index a55fc455c..a3002fb65 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -219,6 +219,9 @@ dependencies { //转换繁体 implementation('com.github.liuyueyi.quick-chinese-transfer:quick-transfer-core:0.2.3') + //加解密类库 + implementation('cn.hutool:hutool-crypto:5.7.19') + //代码编辑com.github.AmrDeveloper:CodeView已集成到应用内 //epubLib集成到应用内 diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index 9b4eecb63..8b289f4bd 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -3,6 +3,8 @@ package io.legado.app.help import android.net.Uri import android.util.Base64 import androidx.annotation.Keep +import cn.hutool.crypto.symmetric.AES +import cn.hutool.crypto.symmetric.DESede import io.legado.app.BuildConfig import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst.dateFormat @@ -688,4 +690,74 @@ interface JsExtensions { return AppConst.androidId } + /** + * AES解密,算法参数经过Base64加密 + * + * @param data 加密的字符串 + * @param key Base64后的密钥 + * @param mode 模式 + * @param padding 补码方式 + * @param iv Base64后的加盐 + * @return 解密后的字符串 + */ + fun aesDecodeArgsBase64Str( + 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) + ).decryptStr(data) + } + + /** + * 3DES解密 + * + * @param data 加密的字符串 + * @param key 密钥 + * @param mode 模式 + * @param padding 补码方式 + * @param iv 加盐 + * @return 解密后的字符串 + */ + fun tripleDESDecodeStr( + data: String, + key: String, + mode: String, + padding: String, + iv: String + ): String? { + return DESede(mode, padding, key.toByteArray(), iv.toByteArray()).decryptStr(data) + } + + /** + * 3DES解密,算法参数经过Base64加密 + * + * @param data 加密的字符串 + * @param key Base64后的密钥 + * @param mode 模式 + * @param padding 补码方式 + * @param iv Base64后的加盐 + * @return 解密后的字符串 + */ + fun tripleDESDecodeArgsBase64Str( + 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) + ).decryptStr(data) + } + }