summaryrefslogtreecommitdiffstats
path: root/src/qca-test.cpp
blob: 73a6b5c1058413deea63f01a22f08546992a245b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * This file is part of MXE. See LICENSE.md for licensing information.
 */

#include <QCoreApplication>
#include <QtCrypto>
#include <QDebug>

#include <iostream>

#ifdef QT_STATICPLUGIN
#include "import_plugins.h"
#endif

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QCA::init();

    QByteArray inputString = "Hello world!";
    if (a.arguments().size() > 1) {
        inputString = a.arguments().at(1).toUtf8();
    }
    std::cout << "input string:\n" << inputString.toStdString() << "\n\n";

    // Calculate hashes of a string with all available hashing algorithms:
    QByteArray outputString;
    for (const QString &hastType : QCA::Hash::supportedTypes()) {
        QCA::Hash hashObject(hastType);
        hashObject.update(inputString);
        outputString = hashObject.final().toByteArray().toHex();

        std::cout << hastType.toStdString() << " hash:\n"
                  << outputString.toStdString() << "\n\n";
    }

    return 0;
}