Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cipherkit

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.


Features

  • 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

Requirements

Dependency Version
CMake ≥ 3.20
C++ Compiler C++17 support required
OpenSSL ≥ 3.0

Install OpenSSL on Debian/Ubuntu:

sudo apt install libssl-dev

Building

Clone the repository:

git clone https://github.com/JR0bin/cipherkit.git
cd cipherkit

Static library (default):

cmake -B build
cmake --build build

Shared library:

cmake -B build -DCIPHERKIT_BUILD_SHARED=ON
cmake --build build

Installing

System-wide (requires sudo):

sudo cmake --install build

Custom prefix (no sudo required):

cmake --install build --prefix ~/.local

After installation, other CMake projects can find cipherkit via find_package():

find_package(cipherkit REQUIRED)
target_link_libraries(myproject PRIVATE cipherkit::cipherkit)

Usage

Key & IV sizes

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_error is thrown.

Example

#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;
    }
}

Using GCM (authenticated encryption)

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");

CMake Integration (without installing)

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)

Generating Documentation

Documentation is generated with Doxygen.

Install Doxygen:

sudo apt install doxygen

Generate (from root folder):

cmake --build build --target docs

Open in browser:

open docs/generated/html/index.html

License

This project is licensed under the MIT License. See LICENSE for details.

About

Simple and easy-to-use library for en- and decryption with openssl

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages