Skip to content

AltheimIcarus/Pi-xcels-solution3

Repository files navigation

Solution for Option 3

This java project contains a native C++ codes to hash and encrypt user's input with a URL to a public key.

Installation

Linux

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

Usage

  1. 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";
  1. Replace the <<CURRENT_WORKING_DIR>> with the exact path to the file libnativeHasher.so in NativeHasher.java:
public class NativeHasher {
    // load the native c++ library
    static {
        System.load("<CURRENT_WORKING_DIR>/libnativeHasher.so");
    }
  1. Compile the java header in bash.
  javac NativeHasher.java
  javah -jni NativeHasher
  1. 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
  1. 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published