【发布时间】:2017-07-20 12:51:52
【问题描述】:
我目前正在为学校做一个项目(比较两个加密函数的运行时间)。所以我搜索了AES。我找到了这个好看的解决方案:https://www.c-plusplus.net/forum/148732
现在,当我将 aes 用作密钥并将 aes 用作明文时,我会得到一个奇怪的结果,其中的字符不是 a-z。
我的完整项目可以查看:https://gogs.4seul.de/root/CryptLaufzeit
void MainWindow::on_pushButtonAesCalc_clicked()
{
//Check if key and plaintext is given (if not -> display alert,if yes -> save in vars)
QString key=ui->lineEditAesKey->text();
QString plaintext=ui->lineEditAesPlaintext->text();
if (key != "" && plaintext != "") {
//Time measure start
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
//Create AES Object
//char array for key and plaintext; length is size_t type and length of char array
size_t sizeKey = key.size();
size_t sizePlain = plaintext.size();
char *plainCharArr = new char [sizePlain];
char *keyCharArr = new char [sizeKey];
memcpy( keyCharArr, key.toStdString().c_str() ,sizeKey);
memcpy( plainCharArr, plaintext.toStdString().c_str() ,sizePlain);
aes AES;
sizePlain = AES.encrypt(&plainCharArr,sizePlain,keyCharArr);
//Time measure end
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
std::time_t end_time = std::chrono::system_clock::to_time_t(end);
//Rerun everything and get steps in between (optional)
//Set values
QMessageBox msgBoxTest;
msgBoxTest.setText(plaintext + "|" + plainCharArr);
msgBoxTest.exec();
} else {
//Display Dialog
QMessageBox msgBox;
msgBox.setText("Bitte fülle alle Felder aus!");
msgBox.exec();
}
}
【问题讨论】:
标签: c++ qt encryption aes