【发布时间】:2020-06-10 15:15:31
【问题描述】:
我有 .net .exe,它监听网络套接字。它在 http 上完美运行。
当我的发件人通过 https 转移到 WSS 时,我的 .exe 无法解密传入的请求。
我的客户端收到字节数组,但是当我尝试将其解密为 UTF 编码时,它无法通过 Encoding.GetEncoding("ISO-8859-1"); 正确解密
代码:
public void ReadCallback(IAsyncResult ar)
{
try
{
// Retrieve the state object
// and the handler socket
// from the asynchronous state object.
var state = (StateObject)ar.AsyncState;
// Read data from the client socket.
var bytesRead = _socket.EndReceive(ar);
// Below code doesn't decrypt correctly for wss
// but works correctly for ws
Utils.Encoding.GetString(state.Buffer, 0, bytesRead);
【问题讨论】:
-
您使用的是什么网络套接字 API?它知道它正在使用 TLS 吗?等等 - 没有一些代码,这很难评论,但概括地说:“是的,如果配置正确,那应该可以工作”
-
` public void ReadCallback(IAsyncResult ar) { try { // 从异步状态对象中检索状态对象 // 和处理程序套接字。 var state = (StateObject)ar.AsyncState; // 从客户端套接字读取数据。 var bytesRead = _socket.EndReceive(ar); ` ** 下面的代码无法正确解密 was,但适用于 ws** ` Utils.Encoding.GetString(state.Buffer, 0, bytesRead) `
-
Encoding.GetsString 没有解密我的流,这就是问题所在。
-
Encoding从不 处理解密 - 这不是Encoding的工作 - 但是:您评论中的代码在这里真的很有帮助;我已将其编辑到问题中,因为它非常重要