From b4ffa4d128c7d2638ea1329b8cfcc48fc2a71322 Mon Sep 17 00:00:00 2001 From: olixina <695176656@qq.com> Date: Wed, 12 Jan 2022 15:54:15 +0800 Subject: [PATCH] feat: add digest encryption method --- .../java/io/legado/app/help/JsExtensions.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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 8b289f4bd..1842aaada 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,7 @@ package io.legado.app.help import android.net.Uri import android.util.Base64 import androidx.annotation.Keep +import cn.hutool.crypto.digest.DigestUtil import cn.hutool.crypto.symmetric.AES import cn.hutool.crypto.symmetric.DESede import io.legado.app.BuildConfig @@ -760,4 +761,32 @@ interface JsExtensions { ).decryptStr(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) + } + }