コード例 #1
0
 public void Login(byte[] encryptedUser, byte[] iv)
 {
     Services.ConnectionInfo connectionInfo = Connections.FindConnection(Context.ConnectionId);
     if (connectionInfo != null && connectionInfo.Status == Services.ConnectionInfo.Statuses.Handshaked)
     {
         string        json     = connectionInfo.Aes.Decrypt(encryptedUser, iv);
         Services.User userInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <Services.User>(json);
         Connections.Login(Context.ConnectionId, userInfo);
     }
 }
コード例 #2
0
 void SendDataToClient <T>(string methodName, byte[] encryptedData, byte[] iv) where T : Services.IDataInfo
 {
     Services.ConnectionInfo connectionInfo = Connections.FindConnection(Context.ConnectionId);
     if (connectionInfo != null && connectionInfo.Status == Services.ConnectionInfo.Statuses.Handshaked)
     {
         string json = connectionInfo.Aes.Decrypt(encryptedData, iv);
         T      key  = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(json);
         connectionInfo = Connections.FindUser(key.User);
         if (connectionInfo != null)
         {
             encryptedData = connectionInfo.Aes.Encrypt(json);
             Clients.Client(connectionInfo.ConnectionID).SendAsync(methodName, encryptedData, connectionInfo.Aes.IV);
         }
     }
 }
コード例 #3
0
 public void EndHandshake(byte[] encryptedAESKey)
 {
     Services.ConnectionInfo connectionInfo = Connections.FindConnection(Context.ConnectionId);
     if (connectionInfo != null && connectionInfo.Status == Services.ConnectionInfo.Statuses.Handshaking)
     {
         byte[] decryptedAESKey;
         try
         {
             decryptedAESKey        = connectionInfo.Rsa.Decrypt(encryptedAESKey);
             connectionInfo.Aes     = new Encryption.CustomAes();
             connectionInfo.Aes.Key = decryptedAESKey;
             connectionInfo.Status  = Services.ConnectionInfo.Statuses.Handshaked;
         }
         catch
         {
         }
     }
 }
コード例 #4
0
        public string BeginHandshake()
        {
            Services.ConnectionInfo connectionInfo = Connections.FindConnection(Context.ConnectionId);

            if (connectionInfo != null)
            {
                if (connectionInfo.Status == Services.ConnectionInfo.Statuses.Connected)
                {
                    connectionInfo.Status = Services.ConnectionInfo.Statuses.Handshaking;
                    connectionInfo.Rsa    = new Encryption.CustomRsa();
                    return(Newtonsoft.Json.JsonConvert.SerializeObject(connectionInfo.Rsa.Public));
                }
                else
                {
                    return("");
                }
            }
            else
            {
                return("");
            }
        }