Android Example:
This example will explain how to use CryptoEngine to write a secure app:
First you need to install these tools (if this is your first Android app using c++):
1- Android SDK (adt-bundle).
2- Android NDK (r10c).
3- Qt5-SDK for Android (I use Qt 5.3.2 ).
This simple example is an app that generete Hash string for any given text using SHA256 algorithm, and here is .pro file for project (named: TestAndroid2):
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = TestAndroid2
TEMPLATE = app
SOURCES += main.cpp\
widget.cpp
HEADERS += widget.h
FORMS += widget.ui
CONFIG += mobility
MOBILITY =
contains(ANDROID_TARGET_ARCH, armeabi-v7a) {
LIBS += -L$$PWD/../../MyProjects/QtCryptoEngine/CryptoEngine/Linux_out/android_armeabi_v7a/ -lCryptoEngine
INCLUDEPATH += $$PWD/../../MyProjects/QtCryptoEngine/CryptoEngine/INCLUDE/CELIB
DEPENDPATH += $$PWD/../../MyProjects/QtCryptoEngine/CryptoEngine/INCLUDE/CELIB
ANDROID_EXTRA_LIBS = \
$$PWD/../../MyProjects/QtCryptoEngine/CryptoEngine/Linux_out/android_armeabi_v7a/libCryptoEngine.so
}
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
OTHER_FILES += \
android/AndroidManifest.xml
contains(ANDROID_TARGET_ARCH, x86) {
LIBS += -L$$PWD/../../MyProjects/QtCryptoEngine/CryptoEngine/Linux_out/android_x86/ -lCryptoEngine
INCLUDEPATH += $$PWD/../../MyProjects/QtCryptoEngine/CryptoEngine/INCLUDE/CELIB
DEPENDPATH += $$PWD/../../MyProjects/QtCryptoEngine/CryptoEngine/INCLUDE/CELIB
ANDROID_EXTRA_LIBS = \
$$PWD/../../MyProjects/QtCryptoEngine/CryptoEngine/Linux_out/android_x86/libCryptoEngine.so
}
The important thing here is that we add CryptoEngine Library (in specific path) as depenency in both: android x86 for Intel Atom architecture, and for armeabi v7a for ARM architecutre which is used now for most smart phones such as Galaxy S4 and Nexus 7; using function contains() - from qmake lang. - then the app will link automatically with the right verssion of library.
You can add only one vesrsion as you need, also you need to add libCryptoEngine.so as extra lib, we do this to ensure that it shipped with app when deploying.
Now we can design a form (QWidget) that contains 4 elements: - Text field (QLineEdit) that used to enter plain text. - Button (QPushButton) which user will click to generate hash. - Text browser (QTextBrowser) that will use to display hash string. - Another button for exit.  Here is widget.cpp:
#include "sha2.h"
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_btnGHash_clicked()
{
const QByteArray plain = ui->le_text->text().toUtf8();
QByteArray hString;
bool isOk;
if(!plain.isEmpty())
{
hString = CELIB::SHA256::hash(plain, &isOk, 0);
if(isOk)
ui->textBrowser->setText(hString.toHex().toUpper());
else
ui->textBrowser->setText("Operation Failed!.");
}
else
ui->textBrowser->clear();
}
void Widget::on_btnExit_clicked()
{
exit(0);
}
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}