[英]AES function giving not the output that I expected
我目前正在做一個學校項目(兩個加密功能的運行時之間的比較)。 所以我搜索了AES。 我找到了一個很好看的解決方案: https : //www.c-plusplus.net/forum/148732
現在,當我將aes
用作鍵aes
並將明文也用作aes
,使用非az
字符會得到奇怪的結果。
我的完整項目可以在以下網址查看: 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();
}
}
AES是一種加密算法。 [a-zA-Z0-9]上的功能未關閉。 意味着您可以在加密的字符串中獲取介於0到256之間的任何值。
如果您仍想可視化加密輸出(出於比較和驗證目的),我建議將每個字節轉換為僅包含可讀字符的十六進制表示形式。
見這個 ,要懂得字節的緩沖區轉換為十六進制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.