- C Bindings for the API of BLAKE3 cryptographic hash function in Java.
- Import maven from Artifactory.
<dependency>
<groupId>vn.zalopay.zas.common.crypto</groupId>
<artifactId>blake3-jni</artifactId>
<version>1.0.0</version>
</dependency>
The library has the same c api:
// Verifies the library is connected
public static boolean isEnabled()
// Creates a NativeBlake3 instance and a equivalent one as `blake3_hasher` in c.
public NativeBlake3() throws IllegalStateException
// Initializers
public void initDefault()
public void initKeyed(byte[] key)
public void initDeriveKey(String context)
// Add input to the hasher. This can be called any number of times.
public void update(byte[] data)
// Equivalent to blake3_hasher_finalize in C. you can keep adding data after calling this.
public byte[] getOutput() throws InvalidNativeOutput
public byte[] getOutput(int outputLength) throws InvalidNativeOutput
- Note: Using in try-with-resources block to auto-close resource allocated in memory in C.
// Initialize the hasher
try (NativeBlake3 hasher = new NativeBlake3()) {
hasher.initDefault();
// read data
byte[] data = "example data".getBytes();
hasher.update(data);
// more data
byte[] moredata = "more data".getBytes();
hasher.update(moredata);
// Finalize the hash. BLAKE3 output length defaults to 32 bytes
byte[] output = hasher.getOutput();
}
-
Currently, this library is build for Linux and Mac OS (M1). detect the OS and load the correct binary.
-
Linux's library is integrated build with Gitlab Runner pipeline. For MacOS build, follow the following guides.
-
For more environment, see here.
-
Requirements:
- Java
- Maven
- GCC
-
Run the command to build native shared library.
$ ./scripts/make.sh
# Output will be native library binaries in `resources` folder.
# libblake3.sylib
- Build jar with Maven.
$ ./scripts/build.sh