Android Question [SOLVED] SHA3-512

rosippc64a

Active Member
Licensed User
Longtime User
Hi All!
I must use the SHA3-512, but I can't find here.
I search in the internet and found some signs about working case, like this and try some simple code, but I have no clue what to do.
My code:

B4X:
...

#AdditionalJar: bcpkix-jdk15on-1.64.jar
...



#if JAVA
import org.bouncycastle.jcajce.provider.digest.SHA3;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

@Test
public void testSha3() throws Exception {
    String input = "Hello world !";
    SHA3.DigestSHA3 digestSHA3 = new SHA3.Digest512();
    byte[] digest = digestSHA3.digest(input.getBytes());

    System.out.println("SHA3-512 = " + Hex.toHexString(digest));
}
#End If
The error:
src\com\lszamla\main.java:3: error: package org.bouncycastle.jcajce.provider.digest does not exist
import org.bouncycastle.jcajce.provider.digest.SHA3;
^
Does anyone have a sha3 library?
 

DonManfred

Expert
Licensed User
Longtime User
did you added the jar with #additionaljar directive?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
because there was a link. I didn't search, just click :)
BUT NOW, when you said "no", I downloaded the bcprov-jdk14-1.64.jar and the compilation is ok.
now I will try whether it will work?
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
huh DonManfred, you are a very clever man! :)

So the result:
B4X:
#AdditionalJar: bcprov-jdk14-1.64.jar
...
Sub test
    Dim nativeMe = Me As JavaObject
    nativeMe.InitializeContext
    Dim s As String = nativeMe.RunMethod("testSha3", Null)
    Log(s)
End Sub
#if JAVA
import org.bouncycastle.jcajce.provider.digest.SHA3;
import org.bouncycastle.util.encoders.Hex;

public String testSha3() throws Exception {
    String input = "Hello world !";
    SHA3.DigestSHA3 digestSHA3 = new SHA3.Digest512();
    byte[] digest = digestSHA3.digest(input.getBytes());

    return "SHA3-512 = " + Hex.toHexString(digest);
}
#End If
the log:
SHA3-512 = e9a4fd120d684537d57f314d51213ce5acef8ff6974e2b7599674ef0f0a3cf111f0d26ed602db946739da448210fb76a7621d7a8f07728372b10a975f36d8e37
looks like it works.
I tried with a bcprov-jdk15on-1.64.jar also, but I got the error:
Convert byte code - optimized dex. Error
PARSE ERROR:
unsupported class file version 53.0
...while parsing META-INF/versions/9/module-info.class
 
Upvote 0
Top