PrivMX DOCS
C++

First app

A step-by-step tutorial that will guide you through creating your first app using PrivMX Endpoint C++ client with PrivMX Bridge.

PrivMX Bridge

To proceed with this tutorial, you should already have your PrivMX Bridge Server up and running. If you don't, you can find step-by-step instructions on quick start page.

Initial Assumptions

All the values below like BRIDGE_URL, SOLUTION_ID, CONTEXT_ID should be replaced by the ones corresponding to your PrivMX Bridge instance.

The private keys here are for demonstration purposes only. Normally, they should be kept separately by each user and stored in a safe place, or generated from a password (see the derivePrivateKey() method in the Crypto API)

The initial assumptions for all the code examples below are as follows:

auto BRIDGE_URL {"http://localhost:9111"};
auto SOLUTION_ID {"YOUR_SOLUTION_ID"};
auto CONTEXT_ID {"YOUR_CONTEXT_ID"};
 
auto USER1_ID {"user_1"};
auto USER1_PUBLIC_KEY {"PUBLIC_KEY_1"};
auto USER1_PRIVATE_KEY {"PRIVATE_KEY_1"};
 
auto USER2_ID {"user_2"};
auto USER2_PUBLIC_KEY {"PUBLIC_KEY_2"};
 
auto USER3_ID {"user_3"};
auto USER3_PUBLIC_KEY {"PUBLIC_KEY_3"};

Create First Client App

First, you have to create a Conan config file in the root dir of your project:

conanfile.txt

[requires]
privmx-endpoint/2.3.3

[generators]
CMakeDeps
CMakeToolchain

[layout]
cmake_layout

Next, add the PrivMX Endpoint library dependency to your CMakeLists.txt:

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project(test_program)
set(CMAKE_CXX_STANDARD 17)
 
find_package(privmxendpoint REQUIRED)
 
add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
target_link_libraries(test_program PUBLIC 
		privmxendpoint::privmxendpointcore 
		privmxendpoint::crypto
)

Now that you have configured the foundation of the application project, you can perform a simple operation using the PriVMX Endpoint library's Crypto API. Let's generate a pair of keys for the user.

main.cpp

#include <optional>
#include <iostream>
#include <privmx/endpoint/crypto/CryptoApi.hpp>
 
using namespace privmx::endpoint::crypto;
int main() {
   auto cryptoApi {CryptoApi::create()};
	auto priv {cryptoApi.generatePrivateKey({})};
	auto pub {cryptoApi.derivePublicKey(priv)};
	std::cout << "Generated private key: " << priv << std::endl
		      << "Generated public key: " << pub << std::endl;
	return 0;
}

Build Project

conan install . --output-folder=build --build=missing
cd build
cmake .. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=build/Release/generators/conan_toolchain.cmake \
        -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release
cmake --build .

Run Project

source build/Release/generators/conanrun.sh
./test_program

We use cookies on our website. We use them to ensure the proper functioning of the site and, if you agree, for purposes we set, such as analytics or marketing.

On this page