LibEncryptMsg

LibEncryptMsg is an open source library, written in C++, which provides encryption and decryption of data and implements OpenPGP specification.

Features

  • Symmetric encryption and decryption
  • Streaming: process large or gradually available data through a buffer
  • Compatibility with other OpenPGP solutions
  • Iterated and salted S2K
  • Cipher algorithms: CAST5, TripleDES, AES128, AES256
  • Hash algorithms: SHA-1, SHA-256, SHA-512
  • Integrity protection: SHA-1
  • Compression: ZLIB, ZIP
  • Integration with Botan crypto library

Projects using this library

EncryptPad - text editor and OpenPGP file encryption utility

Hello World example

#include <fstream>
#include "encryptmsg/message_encryption.h"

int main(int argc, char **argv)
{
    std::string pwd = "swordfish";
    std::string plain_text = "hello world";

    // EncryptMsg::SafeVector is STL vector with a custom allocator as below:
    // std::vector<uint8_t, secure_allocator<uint8_t>>
    EncryptMsg::SafeVector pwd_bytes(pwd.data(), pwd.data() + pwd.size());
    EncryptMsg::SafeVector plain_bytes(plain_text.data(),
        plain_text.data() + plain_text.size());
    EncryptMsg::SafeVector in_out_buffer = plain_bytes;

    EncryptMsg::MessageWriter writer;
    writer.Start(pwd_bytes);
    // Encrypt the buffer and notify that the stream is finished. We could also
    // call writer.Update(in_out_buffer) multiple times if streaming was needed
    writer.Finish(in_out_buffer);

    // Write the data to test.gpg
    std::ofstream file("test.gpg", std::ios_base::binary | std::ios_base::out);
    file.write(reinterpret_cast<const char*>(in_out_buffer.data()),
        in_out_buffer.size());
    return 0;
}

Decrypt test.gpg with GnuPG:

> echo -n "swordfish" | gpg2 --batch --passphrase-fd 0 -d test.gpg
gpg: AES256 encrypted data
gpg: encrypted with 1 passphrase
hello world

Community

Downloads

GitHub releases

Build on Linux

  1. Install the dependencies required to build C++ programs. Ubuntu needs build-essential.

  2. Install pkg-config.

  3. You will also need Botan 2. Ubuntu 18.04 Bionic has an official package: libbotan-2-dev. If your distribution does not have Botan 2 package, you will need to build it and install (link).

  4. In the libencryptmsg source directory, run the three commands:

    ./configure.py [--prefix=/path/to/system/files]
    make
    sudo make install
    

Sometimes you need to call ldconfig as below so that the system can resolve the new so file:

sudo ldconfig

License

LibEncryptMsg Copyright 2018 Evgeny Pokhilko

LibEncryptMsg is released under the Simplified BSD License