public ResponseModel CreateSession([FromBody] KeyRequestModel _clientInfo) { if (_clientInfo.IsValid()) { using (SqlProvider sqlOp = new SqlProvider()) using (RSAOperations keyOp = new RSAOperations()) { string clientId = sqlOp.GetClientId(_clientInfo.ClientSecret); if (!string.IsNullOrEmpty(clientId)) { Tuple <string, string> asymmetricKeyPair = keyOp.GetNewKeyPair(); if (!string.IsNullOrEmpty(asymmetricKeyPair.Item1) && !string.IsNullOrEmpty(asymmetricKeyPair.Item2)) { string sessionEncKey = keyOp.GetSecureRandomString(16); string sessionIvKey = keyOp.GetSecureRandomString(16); while (sessionEncKey.Equals(sessionIvKey)) { sessionIvKey = keyOp.GetSecureRandomString(16); } string newSessionId = sqlOp.CreateClientSession(new Guid(clientId), asymmetricKeyPair.Item2, sessionEncKey, sessionIvKey); if (!string.IsNullOrEmpty(newSessionId)) { return(new ResponseModel() { SessionId = newSessionId, PublicKey = asymmetricKeyPair.Item1 }); } } } } } return(null); }