我正在使用openssl對字符串進行加密,並且得到以空字符結尾的字符串。我現在已經加密了字符串,我想通過使用base64編碼的網絡發送它。我只需要發送加密數據,如何在解密之前計算另一側字符串的長度?C/C++中以null結尾的字符串的長度
unsigned char *plaintext = (unsigned char*) "The quick brown fox jumps sover thes lazy dog";
unsigned char ciphertext[256] = {};
// After using openssl envelope_seal(), with EVP_aes_128_cbc()
strlen((const char*)ciphertext) // length is different each time due to null terminated binary string
sizeof(ciphertext) // lenght is equal to 256
int envelope_seal() // gives me the length of that string as 48.
請幫我計算ciphertext
是48,但沒有在我所知的方法給我正確的輸出的長度。
爲什麼不用字符串本身發送長度? – 2015-02-05 17:08:28
我不知道密碼學的詳細信息,但是如果我需要發送加密文檔,那麼我在哪裏放長度?文件不夠? – Kahn 2015-02-05 17:14:12
「發送加密文件」。通常當談到一個「文檔」時,包含原始二進制數據的char數組並不是立即想到的。如果你有後者,你需要的長度。如果你有一個「文件」,你首先要澄清這個詞的實際含義。 – 2015-02-05 17:27:42