我有一个缓冲区,我正在添加一些纯文本.我想使用openssl AES加密来加密文本,然后将其解密,然后将其打印回屏幕.
代码正在运行,没有错误.
#include#include #include #include #include using namespace std; void main() { // Buffers unsigned char inbuffer[1024]; unsigned char encryptedbuffer[1024]; unsigned char outbuffer[1024]; // CODE FOR ENCRYPTION //-------------------- unsigned char oneKey[] = "abc"; AES_KEY key; AES_set_encrypt_key(oneKey,128,&key); AES_set_decrypt_key(oneKey,128,&key); //-------------------- string straa("hello world\n"); memcpy((char*)inbuffer,straa.c_str(),13); printf("%s",inbuffer); //this prints out fine AES_encrypt(inbuffer,encryptedbuffer,&key); //printf("%s",encryptedbuffer); //this is expected to pring out rubbish, so is commented AES_decrypt(encryptedbuffer,outbuffer,&key); printf("%s",outbuffer); //this is not pringint "hello world" getchar(); }
我知道一旦放入新缓冲区"encryptedbuffer"和"outbuffer",它们不会以空终止"\ 0",但即便如此,通过打印出原始数据,我只是在垃圾后解密,在解密结束时,我假设\ 0也应该被解密,因此printf应该打印corectly.
任何人都知道如何使decyption工作?
还有任何想法如何使用C++库打印缓冲区,也许是cout,而不是printf?