Giter Site home page Giter Site logo

qtinyaes's Introduction

QTinyAes

A Qt-Wrapper for the AES-implementation kokke/tiny-AES-C (supports AES128/192/256)

This class is simply a wrapper for https://github.com/kokke/tiny-AES-C. It allows to use the simple AES-implementation inside Qt and with Qt's QByteArray class. Thanks to recent updates, allowing keys of size 128, 192 and 256.

Features

  • It's a C++-class instead of just C-functions
  • Easy integration with Qt-Projects thanks to the use of QByteArray
  • Allows plain-texts of any size - PKCS#7 Padding is added automatically
  • Supports all common AES keysizes (compile-time switch)
  • Currently supports CTR, CBC and ECB as modes

Installation

The package is provided via qdep, as Skycoder42/QTinyAes. To use it simply:

  1. Install and enable qdep (See qdep - Installing
  2. Add the following to your pro file:
QDEP_DEPENDS += Skycoder42/QTinyAes
!load(qdep):error("Failed to load qdep feature! Run 'qdep.py prfgen --qmake $$QMAKE_QMAKE' to create it.")

Example

QTinyAes aes;

aes.setMode(QTinyAes::CTR);
aes.setKey("randomkey_256bit");// QTinyAes::KeySize (256 bit key by default)
//or with Qt 5.10
aes.setKey(QTinyAes::generateKey());
aes.setIv("random_iv_128bit");// QTinyAes::BlockSize (128 iv vector)

QByteArray plain = "Hello World";
qDebug() << "plain:" << plain
QByteArray cipher = aes.encrypt(plain);
qDebug() << "cipher:" << cipher;
QByteArray result = aes.decrypt(cipher);
qDebug() << "result:" << result;

Changing the key size

By default, your keys must be 256 bit keys. However, you can change this size to 192 or 128 if you need to. This can be done via a qmake variable, as the keysize as a compile time switch (due to limitations of kokke/tiny-AES-C).

To change the size, set the TINYAES_KEYSIZE qmake variable to the desired keysize before loading the qdep feature

TINYAES_KEYSIZE = 128  # or 192 or the default, 256

QDEP_DEPENDS += Skycoder42/QTinyAes
!load(qdep):error("Failed to load qdep feature! Run 'qdep.py prfgen --qmake $$QMAKE_QMAKE' to create it.")

qtinyaes's People

Contributors

skycoder42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

qtinyaes's Issues

Problem compiling on Qt 5.5

Hello,

it seems since your last updates it doesnt compile anymore on Qt 5.5

Error message:

/home/rene/DEV/qtcreator/openfortigui/qtinyaes/qtinyaes.cpp:175: Fehler: no matching function for call to ‘qToBigEndian(quint32, char*)’
     qToBigEndian((quint32)data.size(), dataSize.data());
                                                       ^
/home/rene/DEV/qtcreator/openfortigui/qtinyaes/qtinyaes.cpp:182: Fehler: no matching function for call to ‘qFromBigEndian(const char*)’
     auto dataLen = qFromBigEndian<quint32>(data.constData());
                                                            ^

Seems like on Qt 5.7 the function change its parameter type: http://doc.qt.io/qt-5/qtendian.html#qFromBigEndian

Qt 5.5 would be quite important becaue Ubuntu 16.04 uses this version as default.

Cheers
Rene

void QTinyAes::restorePlainText(QByteArray &data) broken?

data "2019-01-02 " QByteArray &
'2' 50 0x32 char
'0' 48 0x30 char
'1' 49 0x31 char
'9' 57 0x39 char
'-' 45 0x2d char
'0' 48 0x30 char
'1' 49 0x31 char
'-' 45 0x2d char
'0' 48 0x30 char
'2' 50 0x32 char
' ' 32 0x20 char
' ' 32 0x20 char
' ' 32 0x20 char
' ' 32 0x20 char
' ' 32 0x20 char
' ' 32 0x20 char

auto padding = data.at(data.size() - 1);
data.chop((int)padding);

is it necessary set last byte to padding?

padding is 0d32/0x20 here, array is chopped by 32, so result is empty

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.