From e189c3c1c334fa03921e5ef569292e880473ee19 Mon Sep 17 00:00:00 2001 From: Celeter Date: Wed, 23 Oct 2019 22:00:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?MD5Untils=E7=B1=BB=EF=BC=9Ajava=E8=BD=ACkot?= =?UTF-8?q?ln?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/utils/MD5Utils.java | 40 ------------------ .../main/java/io/legado/app/utils/MD5Utils.kt | 42 +++++++++++++++++++ 2 files changed, 42 insertions(+), 40 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/utils/MD5Utils.java create mode 100644 app/src/main/java/io/legado/app/utils/MD5Utils.kt diff --git a/app/src/main/java/io/legado/app/utils/MD5Utils.java b/app/src/main/java/io/legado/app/utils/MD5Utils.java deleted file mode 100644 index d4f0d8a12..000000000 --- a/app/src/main/java/io/legado/app/utils/MD5Utils.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.legado.app.utils; - -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; - } -} diff --git a/app/src/main/java/io/legado/app/utils/MD5Utils.kt b/app/src/main/java/io/legado/app/utils/MD5Utils.kt new file mode 100644 index 000000000..21d6daf3e --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/MD5Utils.kt @@ -0,0 +1,42 @@ +package io.legado.app.utils + +import okhttp3.internal.and +import java.security.MessageDigest +import java.security.NoSuchAlgorithmException + +/** + * 将字符串转化为MD5 + */ + +object MD5Utils { + + fun strToMd5By32(str: String?): String? { + if (str == null) return null + var reStr: String? = null + try { + val md5 = MessageDigest.getInstance("MD5") + val bytes = md5.digest(str.toByteArray()) + val stringBuffer = StringBuilder() + for (b in bytes) { + val bt = b and 0xff + if (bt < 16) { + stringBuffer.append(0) + } + stringBuffer.append(Integer.toHexString(bt)) + } + reStr = stringBuffer.toString() + } catch (e: NoSuchAlgorithmException) { + e.printStackTrace() + } + + return reStr + } + + fun strToMd5By16(str: String): String? { + var reStr = strToMd5By32(str) + if (reStr != null) { + reStr = reStr.substring(8, 24) + } + return reStr + } +} From 120dc9bc4e018a750e30f0baff457e6b292df213 Mon Sep 17 00:00:00 2001 From: Celeter Date: Wed, 23 Oct 2019 22:21:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?MD5Untils=E7=B1=BB=EF=BC=9Ajava=E8=BD=ACkot?= =?UTF-8?q?ln?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/utils/MD5Utils.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/MD5Utils.kt b/app/src/main/java/io/legado/app/utils/MD5Utils.kt index 21d6daf3e..dda1df688 100644 --- a/app/src/main/java/io/legado/app/utils/MD5Utils.kt +++ b/app/src/main/java/io/legado/app/utils/MD5Utils.kt @@ -1,6 +1,5 @@ package io.legado.app.utils -import okhttp3.internal.and import java.security.MessageDigest import java.security.NoSuchAlgorithmException @@ -14,11 +13,11 @@ object MD5Utils { if (str == null) return null var reStr: String? = null try { - val md5 = MessageDigest.getInstance("MD5") - val bytes = md5.digest(str.toByteArray()) - val stringBuffer = StringBuilder() + val md5:MessageDigest = MessageDigest.getInstance("MD5") + val bytes:ByteArray = md5.digest(str.toByteArray()) + val stringBuffer:StringBuilder = StringBuilder() for (b in bytes) { - val bt = b and 0xff + val bt:Int = b.toInt() and 0xff if (bt < 16) { stringBuffer.append(0) }