GithubHelp home page GithubHelp logo

gbrlbsls / plusaes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kkayataka/plusaes

0.0 0.0 0.0 725 KB

Header only C++ AES cipher library

Home Page: https://kkayataka.github.io/plusaes/doc/index.html

License: Boost Software License 1.0

Shell 0.08% C++ 98.69% C 1.04% Objective-C 0.10% Makefile 0.04% M4 0.05%

plusaes's Introduction

plusaes

Header only C++ AES cipher library.

Development Environment

  • Visual Studio 16 2019 (v142)
  • Xcode 11.4 (Apple clang 11.0.0)
  • GCC 4.8.5 (CentOS 7)

Supported block cipher mode

  • ECB
  • CBC
  • GCM
  • CTR (Beta)

Usage

For example, about AES-CBC 128-bit. Encrypts by the plusaes::encrypt_cbc and decripts by the plusaes::decrypt_cbc.

You can use convenient functions like plusaes::key_from_string and plusaes::get_padded_encrypted_size.

#include "plusaes/plusaes.hpp"

#include <string>
#include <vector>

int main() {
    // AES-CBC 128-bit

    // parameters
    const std::string raw_data = "Hello, plusaes";
    const std::vector<unsigned char> key = plusaes::key_from_string(&"EncryptionKey128"); // 16-char = 128-bit
    const unsigned char iv[16] = {
        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
        0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
    };

    // encrypt
    const unsigned long encrypted_size = plusaes::get_padded_encrypted_size(raw_data.size());
    std::vector<unsigned char> encrypted(encrypted_size);

    plusaes::encrypt_cbc((unsigned char*)raw_data.data(), raw_data.size(), &key[0], key.size(), &iv, &encrypted[0], encrypted.size(), true);
    // fb 7b ae 95 d5 0f c5 6f 43 7d 14 6b 6a 29 15 70

    // decrypt
    unsigned long padded_size = 0;
    std::vector<unsigned char> decrypted(encrypted_size);

    plusaes::decrypt_cbc(&encrypted[0], encrypted.size(), &key[0], key.size(), &iv, &decrypted[0], decrypted.size(), &padded_size);
    // Hello, plusaes
}

License

Boost Software License

plusaes's People

Contributors

kkayataka avatar tronic avatar humbertin28dev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.