コード例 #1
0
        private void AcceptConnected(IUser peer, IReadStream readStream,
                                     IWriteStream writeStream)
        {
            var publicKey  = readStream.ShiftRight <string>();
            var key        = ID + "_" + SystemUtil.CreateRandomString(Ssfi.CryptoConfig.CryptonKeyLength);
            var encryptKey = Ssfi.Security.EncryptAesKey(key, publicKey);

            var securityComponent = SecurityComponent.GetObject();

            securityComponent.AesKey     = key;
            securityComponent.Encryptkey = encryptKey;

            peer.AddComponent <ISecurityComponent>(securityComponent);
            Logger.Debug($"添加{nameof(ISecurityComponent)}组件!");

            writeStream.ShiftRight((ushort)encryptKey.Length);
            Logger.Debug("EncryptKey Length:" + encryptKey.Length);
            writeStream.ShiftRight(encryptKey);
            writeStream.ShiftRight(string.Join(";", RpcMethodIds));

            var tmp = readStream.Clone();

            _serverSocket.AddEvent(() => {
                try {
                    _acceptAction.Invoke(peer, readStream);
                } catch (Exception e) {
                    Logger.Error(e);
                }
                tmp.Dispose();
            });
        }