This java project contains a native C++ codes to hash and encrypt user's input with a URL to a public key.
To compile the project on linux, you must first, following dependencies are required to build the project:
sudo apt install cmake
sudo apt-get install libssl-dev
sudo apt-get install libcurl4-openssl-dev
sudo apt-get install nlohmann-json3-dev
git clone https://github.com/microsoft/vcpkg
./vcpkg/bootstrap-vcpkg.sh
./vcpkg/vcpkg install cppcodec
- Setup the URL of which the JWKS json is located at the top of
NativeHasher.cpp
:
/** directive to suppress warning in console,
* 1 = No warning,
* 0 = Show warning
*/
#define SUPPRESS_WARNING 1
const std::string jwksURL = "https://demo.api.piperks.com/.well-known/pi-xcels.json";
- Replace the <<CURRENT_WORKING_DIR>> with the exact path to the file
libnativeHasher.so
inNativeHasher.java
:
public class NativeHasher {
// load the native c++ library
static {
System.load("<CURRENT_WORKING_DIR>/libnativeHasher.so");
}
- Compile the java header in bash.
javac NativeHasher.java
javah -jni NativeHasher
- Compile the C++ native codes with the following cmdlet:
g++ -shared -fPIC -o libnativeHasher.so NativeHasher.cpp -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux -lcurl -lssl -lcrypto -I/usr/include/cppcodec -I/usr/include/nlohmann
If any error occurs when linking the cppcodec library, change the linker flag to:
g++ -shared -fPIC -o libnativeHasher.so NativeHasher.cpp -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux -lcurl -lssl -lcrypto -lcppcodec -I/usr/include/nlohmann
- Run the main java program in bash or compile the jar package:
# Run the java file
java NativeHasher
# OR compile the jar package
jar cmvf MANIFEST.MF NativeHasher.jar NativeHasher.class
# then run with the command
java -jar NativeHasher.jar