【发布时间】:2020-07-01 10:52:05
【问题描述】:
主函数尝试加密并在 logcat 上显示
aes = new ofxLibcrypto();
// start
unsigned char *key = (unsigned char *)"qwertyuiqwertyuiqwertyuiqwertyui";
unsigned char *iv = (unsigned char *)"qwertyuiqwertyui";
unsigned char *plaintext = (unsigned char *)"The quick brown fox jumps over the lazy dog";
unsigned char *ciphertext;
unsigned char decryptedtext[128];
int ciphertext_len, decryptedtext_len;
ciphertext_len = aes->encrypt(plaintext, strlen((char*)plaintext), key, iv, ciphertext);
ofLogNotice("IDB") << "Encrpyted: " << ciphertext;
decryptedtext_len = aes->decrypt(ciphertext, ciphertext_len, key, iv, decryptedtext);
decryptedtext[decryptedtext_len] = (unsigned char) "\0";
ofLogNotice("IDB") << "Decrypted: " << decryptedtext;
// end
程序加密成功,但是当我尝试显示密文时,它只显示第一个字符。当我尝试在循环中按字符显示字符时,它会将所有字符显示为加密。我检查了许多代码来修复它,但他们这样做了,我无法修复它。由于加密和解密功能工作正常,我没有附上它们,但如果需要我会附上。
已经感谢谁会提供帮助。
【问题讨论】:
-
加密是创建一个以 null 结尾的字符串,还是生成二进制 blob?如果它是二进制 blob,则不能将其用作以 null 结尾的字符串并按原样显示。
-
您不能仅通过打印来显示加密文本。通常通过将二进制数据转换为十六进制来显示。
标签: c++ encryption openssl aes