Skip to main content
java

Privmx Endpoint Java

Initial Requirements

To start developing end-to-end encrypted applications using PrivMX Endpoint you need:

  • A PrivMX Bridge instance, you can find installation guide here. To connect it to your environment you will need these API keys:

    • SolutionID - created inside your Organization;
    • Platform URL - unique for your Instance;
    • ContextID - there can be one or more depending on the use case.
  • A server for managing users. It can be new or existing, depending on the specific requirements. For more information about how PrivMX Endpoint integrates into your stack check our getting started guide.

Installation

Our Java libraries contain all the necessary assets and helpers to get started with PrivMX Endpoint. Select which level is the best for you. Go to Java overview to see the descriptions of each library.

Java Dependencies

  1. Add mavenCentral() repository to your settings.gradle:
dependencyResolutionManagement{
repositories{
mavenCentral()
}
}
  1. Add dependency to build.gradle:
dependencies {
def privmxLibVersion = "2.0" // privmx-endpoint-version
implementation("com.simplito.java:privmx-endpoint-extra:$privmxLibVersion")
//implementation("com.simplito.java:privmx-endpoint:$privmxLibVersion") #for base Java library
//implementation("com.simplito.java:privmx-endpoint-android:$privmxLibVersion") #for Android Java library
}

Shared Libraries

Java projects require you to install shared native libraries in a specified path and pass this path to java command as argument -Djava.library.path=. In Android, you just need to put the libraries in the src/main/jniLibs directory.

Use our gradle plugin to download and unzip the shared libraries.
Alternatively, download them from our repository with the same version as your privmx-endpoint-java library.

  1. Add mavenCentral() repository to your settings.gradle:
pluginManagement {
repositories{
mavenCentral()
}
}
  1. Add and configure the plugin in build.gradle:
plugins {
id "com.simplito.privmx-endpoint-install-native" version "$pluginVersion"
}

privmxEndpointInstallJni{
version = $nativeLibVersion // this version should be the same as privmx-endpoint-java version
}

For more information about the plugin, go to its dedicated section.

Connecting to PrivMX Bridge

To use any of the library's elements, you must first connect to PrivMX Bridge. Use the API keys mentioned earlier:

String pathToCerts = "PATH_TO_CERTS"; // Path to .pem ssl certificate to connect with Privmx Bridge

String privKey = "USER_PRIVATE_KEY"; // user's private key
String solutionId = "SOLUTION_ID"; // your solution ID
String platformUrl = "PLATFORM_URL"; // your platform url
Set<Modules> modules = Set.of(
Modules.THREAD, // initialises ThreadApi to working with Threads
Modules.STORE, // initialises StoreApi to working with Stores
Modules.INBOX // initialises InboxApi to working with Inboxes
); // list of modules to activate in this connection

// Your role is to provide a valid PrivateKey to match the Public Key already assigned to the Bridge's Context.
// Alternatively you can generate it with our helper function such as
// endpointContainer.cryptoApi.derivePrivateKey(from: "/*secret*/", and: "/*salt*/").

PrivmxEndpointContainer container = new PrivmxEndpointContainer();
container.setCertsPath(pathToCerts);

PrivmxEndpoint connection = container.connect(
modules,
privKey,
solutionId,
platformUrl
);

The active connection is kept by container and can be accessed using container.pivmxEndpoint getter.

Disconnecting from PrivMX Bridge

container.disconnect(connection.connection.connectionId)

Closing PrivmxEndpointContainer

When you finish working with the container, close it to end all connections, close the event loop, and release the resources being used. You can also use a try-with-resources block in Java or use function in Kotlin.

container.close()

Next Steps

With everything ready to go, now it's time to start using all of the Platform's capabilities.

Learn how to use:

  • Threads - for exchanging encrypted messages;
  • Stores - for saving and sharing encrypted files.