1
0
mirror of https://github.com/etesync/android synced 2024-11-15 20:38:58 +00:00

Implement sha256 using bouncy-castle.

This commit is contained in:
Tom Hacohen 2017-02-22 18:49:51 +00:00
parent 7a80b37818
commit 94b29e86ac

View File

@ -16,6 +16,7 @@ import org.spongycastle.crypto.paddings.PKCS7Padding;
import org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher; import org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher;
import org.spongycastle.crypto.params.KeyParameter; import org.spongycastle.crypto.params.KeyParameter;
import org.spongycastle.crypto.params.ParametersWithIV; import org.spongycastle.crypto.params.ParametersWithIV;
import org.spongycastle.jcajce.provider.digest.SHA256;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
import java.security.MessageDigest; import java.security.MessageDigest;
@ -119,13 +120,11 @@ public class Helpers {
} }
static String sha256(byte[] base) { static String sha256(byte[] base) {
try { SHA256Digest digest = new SHA256Digest();
MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.update(base, 0, base.length);
byte[] hash = digest.digest(base); byte[] ret = new byte[digest.getDigestSize()];
return toHex(hash); digest.doFinal(ret, 0);
} catch (Exception ex) { return toHex(ret);
throw new RuntimeException(ex);
}
} }
public static String toHex(byte[] bytes) { public static String toHex(byte[] bytes) {