public override bool Decrypt(NetIncomingMessage msg) { int unEncLenBits = (int)msg.ReadUInt32(); var ms = new MemoryStream(msg.m_data, 4, msg.LengthBytes - 4); var cs = GetDecryptStream(ms); var result = m_peer.GetStorage(unEncLenBits); cs.Read(result, 0, NetUtility.BytesToHoldBits(unEncLenBits)); cs.Close(); // TODO: recycle existing msg msg.m_data = result; msg.m_bitLength = unEncLenBits; return true; }
public override bool Decrypt(NetIncomingMessage msg) { int unEncLenBits = (int)msg.ReadUInt32(); var ms = new MemoryStream(msg.m_data, 4, msg.LengthBytes - 4); var cs = new CryptoStream(ms, m_algorithm.CreateDecryptor(), CryptoStreamMode.Read); var byteLen = NetUtility.BytesToHoldBits(unEncLenBits); var result = m_peer.GetStorage(byteLen); cs.Read(result, 0, byteLen); cs.Close(); // TODO: recycle existing msg msg.m_data = result; msg.m_bitLength = unEncLenBits; msg.m_readPosition = 0; return true; }