Simple, lightweight C++ file encryption library built on top of OpenSSL.
cipherkit wraps OpenSSL's EVP API into a clean, modern C++17 interface. Encrypt and decrypt files with a single function call using AES-128-CBC, AES-256-CBC, or AES-256-GCM.
- AES-128-CBC, AES-256-CBC, AES-256-GCM file encryption
- GCM authentication tag verification on decrypt
- Builds as static or shared library
- CMake install support with proper
find_package()integration
| Dependency | Version |
|---|---|
| CMake | ≥ 3.20 |
| C++ Compiler | C++17 support required |
| OpenSSL | ≥ 3.0 |
Install OpenSSL on Debian/Ubuntu:
sudo apt install libssl-devClone the repository:
git clone https://github.com/JR0bin/cipherkit.git
cd cipherkitStatic library (default):
cmake -B build
cmake --build buildShared library:
cmake -B build -DCIPHERKIT_BUILD_SHARED=ON
cmake --build buildSystem-wide (requires sudo):
sudo cmake --install buildCustom prefix (no sudo required):
cmake --install build --prefix ~/.localAfter installation, other CMake projects can find cipherkit via find_package():
find_package(cipherkit REQUIRED)
target_link_libraries(myproject PRIVATE cipherkit::cipherkit)| Cipher | Key | IV |
|---|---|---|
AES_128_CBC |
16 bytes | 16 bytes |
AES_256_CBC |
32 bytes | 16 bytes |
AES_256_GCM |
32 bytes | 12 bytes |
Note: AES-256-GCM appends a 16-byte authentication tag to the ciphertext. If the tag does not match on decryption, a
std::runtime_erroris thrown.
#include <cipherkit/cipherkit.hpp>
#include <iostream>
int main()
{
const std::string key(32, 'A'); // 32 bytes for AES-256
const std::string iv(16, 'B'); // 16 bytes for CBC
try {
// Encrypt
cipherkit::encrypt(cipherkit::Cipher::AES_256_CBC, key, iv,
"document.pdf", "document.pdf.enc");
// Decrypt
cipherkit::decrypt(cipherkit::Cipher::AES_256_CBC, key, iv,
"document.pdf.enc", "document_out.pdf");
std::cout << "Done.\n";
}
catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << '\n';
return 1;
}
}const std::string key(32, 'K'); // 32 bytes
const std::string iv(12, 'I'); // 12 bytes for GCM
cipherkit::encrypt(cipherkit::Cipher::AES_256_GCM, key, iv,
"secret.bin", "secret.bin.enc");
// Throws std::runtime_error if authentication tag does not match
cipherkit::decrypt(cipherkit::Cipher::AES_256_GCM, key, iv,
"secret.bin.enc", "secret.bin.out");You can use cipherkit directly by pointing to the source directory:
add_library(cipherkit STATIC IMPORTED)
set_target_properties(cipherkit PROPERTIES
IMPORTED_LOCATION /path/to/cipherkit/lib/libcipherkit.a
)
target_include_directories(myproject PRIVATE /path/to/cipherkit/include)
target_link_libraries(myproject PRIVATE cipherkit OpenSSL::SSL OpenSSL::Crypto)Documentation is generated with Doxygen.
Install Doxygen:
sudo apt install doxygenGenerate (from root folder):
cmake --build build --target docsOpen in browser:
open docs/generated/html/index.htmlThis project is licensed under the MIT License. See LICENSE for details.