我一直在關注SSL/TLS在線教程(以及更多的閱讀傢伙源代碼和跟隨),但是我用這個EncryptMessage部分碰到了一條崎嶇不平的道路,因爲它將數據推開並加密錯誤的信息。C++ - EncryptMessage不加密正確的數據
的pbloBuffer,我送它是:
GET/HTTP/1.1\r\n
HOST: www.google.com\r\n\r\n
但是當我做pbMessage = pbloBuffer + Sizes.cbHeader;我結束了(即使是微軟的網站說,要做到這一點)
1\r\n
HOST: www.google.com\r\n\r\n
現在pbMessage是上面的代碼,而這SECBUFFER_DATA下插入,它甚至沒有得到完整的數據。根據我的理解,SECBUFFER_DATA是Web服務器將解碼和處理的「用戶」數據。
你能找到如何解決這個問題並正確發送加密數據嗎?
全部源:(此代碼是實驗性的,因爲我想了解它,我做出改變之前)
int Adaptify::EncryptSend(PBYTE pbloBuffer, int Size) {
SECURITY_STATUS scRet{ 0 };
SecBufferDesc Message{ 0 };
SecBuffer Buffers[4]{ 0 };
DWORD cbMessage = 0, cbData = 0;
PBYTE pbMessage = nullptr;
SecPkgContext_StreamSizes Sizes = { 0 };
QueryContextAttributesW(&hContext, SECPKG_ATTR_STREAM_SIZES, &Sizes);
pbMessage = pbloBuffer + Sizes.cbHeader;
cbMessage = (DWORD)strlen((const char*)pbMessage);
Buffers[0].BufferType = SECBUFFER_STREAM_HEADER;
Buffers[0].cbBuffer = Sizes.cbHeader;
Buffers[0].pvBuffer = pbloBuffer;
Buffers[1].BufferType = SECBUFFER_DATA;
Buffers[1].pvBuffer = pbMessage;
Buffers[1].cbBuffer = cbMessage;
Buffers[2].BufferType = SECBUFFER_STREAM_TRAILER;
Buffers[2].cbBuffer = Sizes.cbTrailer;
Buffers[2].pvBuffer = pbMessage + cbMessage;
Buffers[3].BufferType = SECBUFFER_EMPTY;
Buffers[3].cbBuffer = SECBUFFER_EMPTY;
Buffers[3].pvBuffer = SECBUFFER_EMPTY;
Message.cBuffers = 4;
Message.pBuffers = Buffers;
Message.ulVersion = SECBUFFER_VERSION;
scRet = EncryptMessage(&hContext, 0, &Message, 0);
if (send(hSocket, (const char*)pbloBuffer, Buffers[0].cbBuffer + Buffers[1].cbBuffer + Buffers[2].cbBuffer, 0) < 0) {
MessageBox(0, L"Send error", 0, 0);
}
return 0;
}
複製你的消息,謝謝!(我通過傢伙源代碼閱讀,我發現他甚至在他稱之爲SendEncrypt函數之前轉移了一切。 我感謝您的幫助。 –