From 601031e55d6f0bcb6b75e17150dd166e1c539e04 Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Mon, 14 Dec 2020 18:17:13 +0100 Subject: [PATCH] Replace Hex class from GMS with the one from Apache --- app/build.gradle | 1 + app/src/main/java/io/lbry/browser/utils/Helper.java | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 16350e27..58922d5b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -119,6 +119,7 @@ dependencies { implementation 'com.arthenica:mobile-ffmpeg-full-gpl:4.3.1.LTS' + implementation 'commons-codec:commons-codec:1.15' implementation 'org.bitcoinj:bitcoinj-tools:0.14.7' implementation 'org.java-websocket:Java-WebSocket:1.5.1' diff --git a/app/src/main/java/io/lbry/browser/utils/Helper.java b/app/src/main/java/io/lbry/browser/utils/Helper.java index 6d6a3862..73bfa10f 100644 --- a/app/src/main/java/io/lbry/browser/utils/Helper.java +++ b/app/src/main/java/io/lbry/browser/utils/Helper.java @@ -29,9 +29,8 @@ import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import com.google.android.gms.common.util.Hex; +import org.apache.commons.codec.binary.Hex; -import org.bitcoinj.core.Base58; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -39,7 +38,7 @@ import org.json.JSONObject; import java.io.Closeable; import java.io.File; import java.io.IOException; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.text.DecimalFormat; @@ -795,9 +794,9 @@ public final class Helper { public static String SHA256(String value) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); - byte[] hash = digest.digest(value.getBytes("UTF-8")); - return Hex.bytesToStringLowercase(hash); - } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) { + byte[] hash = digest.digest(value.getBytes(StandardCharsets.UTF_8)); + return Hex.encodeHexString(hash, true); + } catch (NoSuchAlgorithmException ex) { return null; } }