From 94b29e86ac4b293c207010cfc1fa97e8d5ef7959 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 22 Feb 2017 18:49:51 +0000 Subject: [PATCH] Implement sha256 using bouncy-castle. --- .../at/bitfire/davdroid/journalmanager/Helpers.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/journalmanager/Helpers.java b/app/src/main/java/at/bitfire/davdroid/journalmanager/Helpers.java index 55ccfe2e..e94c5b52 100644 --- a/app/src/main/java/at/bitfire/davdroid/journalmanager/Helpers.java +++ b/app/src/main/java/at/bitfire/davdroid/journalmanager/Helpers.java @@ -16,6 +16,7 @@ import org.spongycastle.crypto.paddings.PKCS7Padding; import org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher; import org.spongycastle.crypto.params.KeyParameter; import org.spongycastle.crypto.params.ParametersWithIV; +import org.spongycastle.jcajce.provider.digest.SHA256; import org.spongycastle.util.encoders.Hex; import java.security.MessageDigest; @@ -119,13 +120,11 @@ public class Helpers { } static String sha256(byte[] base) { - try { - MessageDigest digest = MessageDigest.getInstance("SHA-256"); - byte[] hash = digest.digest(base); - return toHex(hash); - } catch (Exception ex) { - throw new RuntimeException(ex); - } + SHA256Digest digest = new SHA256Digest(); + digest.update(base, 0, base.length); + byte[] ret = new byte[digest.getDigestSize()]; + digest.doFinal(ret, 0); + return toHex(ret); } public static String toHex(byte[] bytes) {