Created
June 21, 2017 07:55
-
-
Save NorbertFenk/1ba340500b90216ba0b3b600a9b91cb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <QString> | |
#include <QByteArray> | |
#include <QDebug> | |
#include <QFile> | |
#include <QCryptographicHash> | |
#include <botan/pkcs8.h> | |
#include <botan/hex.h> | |
#include <botan/pk_keys.h> | |
#include <botan/pubkey.h> | |
#include <botan/auto_rng.h> | |
#include <botan/rng.h> | |
#include <botan/rsa.h> | |
#include <botan/data_src.h> | |
#include <botan/x509self.h> | |
QString readInput (const QString &filePath) | |
{ | |
return QString(); | |
} | |
std::vector<uint8_t> convertQStringToStdVector(const QString &string) | |
{ | |
std::string stdString = string.toStdString(); | |
std::vector<uint8_t> rawTextVector(stdString.data(), stdString.data()+stdString.length()); | |
// std::cout << "vec: " << plaintextVector.size() << std::endl; | |
// for (auto it : rawTextVector) { | |
// std::cout << it << std::endl; | |
// } | |
return rawTextVector; | |
} | |
std::vector<uint8_t> convertQByteArrayToStdVector(const QByteArray &array) | |
{ | |
std::string stdString = array.toStdString(); | |
std::vector<uint8_t> rawStdVector(stdString.data(), stdString.data()+stdString.length()); | |
// std::cout << "vec: " << plaintextVector.size() << std::endl; | |
// for (auto it : rawTextVector) { | |
// std::cout << it << std::endl; | |
// } | |
return rawStdVector; | |
} | |
Botan::Private_Key *generateKeys(Botan::RSA_PrivateKey RSAKey, Botan::AutoSeeded_RNG *rng) | |
{ | |
return nullptr; | |
} | |
QString makeCert(Botan::Private_Key *keys, Botan::AutoSeeded_RNG *rng) | |
{ | |
return QString(); | |
} | |
QByteArray generateHash(const QString &data) | |
{ | |
return QByteArray(); | |
} | |
std::vector<uint8_t> encryptData(Botan::Private_Key *keys, Botan::AutoSeeded_RNG *rng, const std::vector<uint8_t> &dataVector) | |
{ | |
return std::vector<uint8_t>(); | |
} | |
std::vector<uint8_t> signData(Botan::Private_Key *keys, Botan::AutoSeeded_RNG *rng, const std::vector<uint8_t> &dataVector) | |
{ | |
return std::vector<uint8_t>(); | |
} | |
bool verifyData(Botan::Private_Key *keys, const std::vector<uint8_t> &dataVector, const std::vector<uint8_t> &signature) | |
{ | |
return false; | |
} | |
QByteArray decryptData(Botan::Private_Key *keys, Botan::AutoSeeded_RNG *rng, const std::vector<uint8_t> &dataVector) | |
{ | |
return QByteArray(); | |
} | |
int main (int argc, char* argv[]) | |
{ | |
if (argc != 2) { | |
qDebug() << "Please add a valid file path"; | |
qDebug() << argv[0] << " <file path>"; | |
return 1; | |
} | |
Q_UNUSED(argc); | |
QString rawInput = readInput(argv[1]); | |
qDebug() << rawInput << endl; | |
Botan::AutoSeeded_RNG rng; | |
Botan::RSA_PrivateKey RSAKey(rng, 2048); | |
Botan::RSA_PrivateKey RSAKey2(rng, 2048); | |
Botan::Private_Key *keys = generateKeys(RSAKey, &rng); | |
Botan::Private_Key *keys2 = generateKeys(RSAKey2, &rng); | |
qDebug() << makeCert(keys, &rng) << endl; | |
QByteArray hash = generateHash(rawInput); | |
qDebug() << "hashed data: " << hash.toHex() << endl; | |
std::vector<uint8_t> hashVector = convertQByteArrayToStdVector(hash); | |
std::vector<uint8_t> dataVector = convertQStringToStdVector(rawInput); | |
std::vector<uint8_t> ciphertext = encryptData(keys, &rng, hashVector); | |
std::vector<uint8_t> ciphertextOfStringInput = encryptData(keys, &rng, dataVector); | |
std::vector<uint8_t> signature = signData(keys, &rng, ciphertext); | |
std::vector<uint8_t> signatureOfStringInput = signData(keys, &rng, ciphertextOfStringInput); | |
qDebug() << "Signature: " << Botan::hex_encode(signature).c_str() << endl; | |
qDebug() << "Message is { " << (verifyData(keys, ciphertext, signature) ? "valid" : "invalid") << " }" << endl; | |
qDebug() << "Message is { " << (verifyData(keys2, ciphertext, signature) ? "valid" : "invalid") << " }" << endl; | |
qDebug() << "Message is { " << (verifyData(keys, ciphertextOfStringInput, signatureOfStringInput) ? "valid" : "invalid") << " }" << endl; | |
qDebug() << "decoded: " << decryptData(keys, &rng, ciphertext).toHex() << endl; | |
qDebug() << "hash: " << hash.toHex() << endl; | |
qDebug() << "decoded text: " << QString::fromUtf8(decryptData(keys, &rng, ciphertextOfStringInput)) << endl; | |
qDebug() << "original text: " << rawInput << endl; | |
delete keys; | |
delete keys2; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment