From 9fafda85dc28f561707b62bf218ef4a3620db746 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 23 Oct 2019 14:03:30 +0800 Subject: [PATCH] up --- .../java/io/legado/app/help/JsExtensions.kt | 9 ++++ .../app/model/analyzeRule/AnalyzeRule.kt | 8 ++++ .../java/io/legado/app/utils/MD5Utils.java | 44 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 app/src/main/java/io/legado/app/utils/MD5Utils.java 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 d449d553c..f317c52b5 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -2,6 +2,7 @@ package io.legado.app.help import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.EncoderUtils +import io.legado.app.utils.MD5Utils import io.legado.app.utils.StringUtils import java.util.regex.Pattern @@ -46,4 +47,12 @@ class JsExtensions { } } + fun strToMd5By32(str: String?): String? { + return MD5Utils.strToMd5By32(str) + } + + fun strToMd5By16(str: String?): String? { + return MD5Utils.strToMd5By16(str) + } + } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 5a5cda401..cba7bc0f1 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -592,6 +592,14 @@ class AnalyzeRule(private var book: BaseBook? = null) { } } + fun strToMd5By32(str: String?): String? { + return MD5Utils.strToMd5By32(str) + } + + fun strToMd5By16(str: String?): String? { + return MD5Utils.strToMd5By16(str) + } + companion object { private val putPattern = Pattern.compile("@put:(\\{[^}]+?\\})", Pattern.CASE_INSENSITIVE) private val getPattern = Pattern.compile("@get:\\{([^}]+?)\\}", Pattern.CASE_INSENSITIVE) diff --git a/app/src/main/java/io/legado/app/utils/MD5Utils.java b/app/src/main/java/io/legado/app/utils/MD5Utils.java new file mode 100644 index 000000000..8b955b922 --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/MD5Utils.java @@ -0,0 +1,44 @@ +package io.legado.app.utils; + +/** + * Created by newbiechen on 2018/1/1. + */ + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * 将字符串转化为MD5 + */ + +public class MD5Utils { + + public static String strToMd5By32(String str) { + if (str == null) return null; + String reStr = null; + try { + MessageDigest md5 = MessageDigest.getInstance("MD5"); + byte[] bytes = md5.digest(str.getBytes()); + StringBuilder stringBuffer = new StringBuilder(); + for (byte b : bytes) { + int bt = b & 0xff; + if (bt < 16) { + stringBuffer.append(0); + } + stringBuffer.append(Integer.toHexString(bt)); + } + reStr = stringBuffer.toString(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return reStr; + } + + public static String strToMd5By16(String str) { + String reStr = strToMd5By32(str); + if (reStr != null) { + reStr = reStr.substring(8, 24); + } + return reStr; + } +}