public async Task <ActionResult <TSCategory> > Get([FromBody] TSCategory TSCategory)
        {
            string UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(UserID, "Requested Category", MethodBase.GetCurrentMethod());

            SymmKeyAndIV ClientSymmKeyAndIV = new SymmKeyAndIV
            {
                Key = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmKey", 5),
                IV  = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmIV", 10)
            };


            if (!string.IsNullOrEmpty(ClientSymmKeyAndIV.Key))
            {
                TSCategory result = await TS.GetCategory(TSCategory);

                GlobalFunctions.CmdEncryptEntitySymm(result, ClientSymmKeyAndIV);


                return(result);
            }
            else
            {
                return(new TSCategory());
            }
        }
        public async Task <ActionResult> Delete([FromBody] TSUser tsUser)
        {
            string UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(UserID, "delete user", MethodBase.GetCurrentMethod());

            SymmKeyAndIV ClientSymmKeyAndIV = new SymmKeyAndIV();

            ClientSymmKeyAndIV.Key = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmKey", 5);
            ClientSymmKeyAndIV.IV  = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmIV", 10);

            if (!ClientSymmKeyAndIV.Key.Equals("Error"))
            {
                GlobalFunctions.CmdDecryptEntitySymm(tsUser, ClientSymmKeyAndIV);

                bool b = await TS.DeleteUser(tsUser);

                if (b)
                {
                    return(Ok());
                }
                else
                {
                    return(UnprocessableEntity());
                }
            }
            else
            {
                return(BadRequest("Can't get crypto key!"));
            }
        }
        public async Task <ActionResult <IEnumerable <TSCategory> > > GetAll()
        {
            string UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(UserID, "Requested Categories", MethodBase.GetCurrentMethod());


            SymmKeyAndIV ClientSymmKeyAndIV = new SymmKeyAndIV
            {
                Key = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmKey", 5),
                IV  = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmIV", 10)
            };


            if (!string.IsNullOrEmpty(ClientSymmKeyAndIV.Key))
            {
                List <TSCategory> list = await TS.GetAllCategories(GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10));

                foreach (var item in list)
                {
                    GlobalFunctions.CmdEncryptEntitySymm(item, ClientSymmKeyAndIV);
                }

                return(list);
            }
            else
            {
                return(new List <TSCategory>());
            }
        }
        public async Task <ActionResult <IEnumerable <TSUser> > > Get()
        {
            string UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(UserID, "Requested all users", MethodBase.GetCurrentMethod());

            List <TSUser> users = new List <TSUser>();

            SymmKeyAndIV ClientSymmKeyAndIV = new SymmKeyAndIV();

            ClientSymmKeyAndIV.Key = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmKey", 5);
            ClientSymmKeyAndIV.IV  = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmIV", 10);

            if (!ClientSymmKeyAndIV.Key.Equals("Error"))
            {
                users = await TS.GetAllUsers();

                for (int i = 0; i < users.Count; i++)
                {
                    GlobalFunctions.CmdEncryptEntitySymm(users[0], ClientSymmKeyAndIV);
                }
            }
            else
            {
                return(BadRequest("Can't get crypto key!"));
            }

            return(users);
        }
        public async Task <ActionResult <TSFeedback> > GetFeedback()
        {
            string userID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(userID, "Requested Feedback", MethodBase.GetCurrentMethod());

            SymmKeyAndIV ClientSymmKeyAndIV = new SymmKeyAndIV
            {
                Key = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmKey", 5),
                IV  = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmIV", 10)
            };


            if (!string.IsNullOrEmpty(ClientSymmKeyAndIV.Key))
            {
                TSFeedbackEntity feedbackEntity = await TS.FindFeedback(userID, true, string.Empty);


                if (feedbackEntity != null)
                {
                    TSFeedback result = feedbackEntity.toTSFeedback();

                    GlobalFunctions.CmdEncryptEntitySymm(result, ClientSymmKeyAndIV);

                    return(result);
                }
                else
                {
                    return(new TSFeedback());
                }
            }
            else
            {
                return(new TSFeedback());
            }
        }
        public async Task <ActionResult <IEnumerable <TSUserOpen> > > GetLiveUsers()
        {
            string userID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);

            await TS.AddActivityLog(userID, "get live users", MethodBase.GetCurrentMethod());

            SymmKeyAndIV ClientSymmKeyAndIV = new SymmKeyAndIV();

            ClientSymmKeyAndIV.Key = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmKey", 5);
            ClientSymmKeyAndIV.IV  = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmIV", 10);

            if (!ClientSymmKeyAndIV.Key.Equals("Error"))
            {
                List <TSUserOpen> a = await TS.GetLiveUsers();

                foreach (var item in a)
                {
                    GlobalFunctions.CmdEncryptEntitySymm(item, ClientSymmKeyAndIV);
                }

                return(a);
            }
            else
            {
                return(BadRequest("Can't get crypto key!"));
            }
        }
        public async Task <ActionResult <IEnumerable <TSFeedback> > > GetAllFeedback()
        {
            string userID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);

            await TS.AddActivityLog(userID, "Requested Feedbacks", MethodBase.GetCurrentMethod());


            SymmKeyAndIV ClientSymmKeyAndIV = new SymmKeyAndIV
            {
                Key = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmKey", 5),
                IV  = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmIV", 10)
            };


            if (!string.IsNullOrEmpty(ClientSymmKeyAndIV.Key))
            {
                List <TSFeedback> list = await TS.GetAllFeedback();

                foreach (var item in list)
                {
                    item.UserName = TS.FindUser(item.UserID, true, string.Empty).Result.FullName;
                    GlobalFunctions.CmdEncryptEntitySymm(item, ClientSymmKeyAndIV);
                }

                return(list);
            }
            else
            {
                return(new List <TSFeedback>());
            }
        }
Beispiel #8
0
        public static void CmdDecryptEntitySymm <T>(T Par_entity, SymmKeyAndIV ParSymmKeyAndIV)
        {
            string tmp_str = string.Empty;

            foreach (PropertyInfo item in typeof(T).GetProperties().Where(x => x.PropertyType == typeof(string)))
            {
                tmp_str = (string)item.GetValue(Par_entity);
                if (!string.IsNullOrEmpty(tmp_str))
                {
                    item.SetValue(Par_entity, CmdSymmetricDecrypt(tmp_str, ParSymmKeyAndIV));
                }
            }
        }
        public async Task <ActionResult <TSUser> > Authorize([FromBody] TSUser tsUser)
        {
            string UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(UserID, "Requested authentication", MethodBase.GetCurrentMethod());

            TSUser result = new TSUser();

            SymmKeyAndIV ClientSymmKeyAndIV = new SymmKeyAndIV
            {
                Key = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmKey", 5),
                IV  = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmIV", 10)
            };


            if (!string.IsNullOrEmpty(ClientSymmKeyAndIV.Key))
            {
                GlobalFunctions.CmdDecryptEntityAsymm(tsUser);

                tsUser.UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);

                result = TS.GetUser(tsUser).Result;

                if (!string.IsNullOrEmpty(result.UserID))
                {
                    await GlobalFunctions.NotifyAdmin("New login " + result.UserName);

                    await TS.UpdateSettingCounter("AllUsers", "LiveUsersCount", true);

                    GlobalFunctions.CmdEncryptEntitySymm(result, ClientSymmKeyAndIV);
                }
                else
                {
                    result.UserName = "******";
                    result.FullName = "Can't find user!";
                    GlobalFunctions.CmdEncryptEntitySymm(result, ClientSymmKeyAndIV);
                }
            }
            else
            {
                result.UserName = "******";
                result.FullName = "Can't get crypto key!";
            }

            return(result);
        }
Beispiel #10
0
        public static string CmdGetPublicData()
        {
            SymmKeyAndIV tmpSymmKeyAndIV = new SymmKeyAndIV();

            using (Aes myAes = Aes.Create())
            {
                tmpSymmKeyAndIV.Key = Convert.ToBase64String(myAes.Key);
                tmpSymmKeyAndIV.IV  = Convert.ToBase64String(myAes.IV);
            }

            string publickey = CmdSymmetricEncrypt(GetSalt() + GlobalData.ServerAsymmetricPublicKey + GetSalt(), tmpSymmKeyAndIV);

            string NotAuthorizedUser = CmdSymmetricEncrypt(GetSalt() + GlobalData.NotAuthorizedUserName + GlobalData.NotAuthorizedUserPass + GetSalt(), tmpSymmKeyAndIV);

            tmpSymmKeyAndIV.Key = GetSalt() + tmpSymmKeyAndIV.Key + GetSalt();
            tmpSymmKeyAndIV.IV  = GetSalt() + GetSalt() + tmpSymmKeyAndIV.IV + GetSalt() + GetSalt();

            return(GetSalt() + publickey + NotAuthorizedUser + tmpSymmKeyAndIV.IV + tmpSymmKeyAndIV.Key + GetSalt());
        }
        public async Task <ActionResult <TSReaction> > AddReaction([FromBody] TSReaction TSReaction)
        {
            TSReaction.UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(TSReaction.UserID, "Add or update Reaction", MethodBase.GetCurrentMethod());

            string userName = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserName", 10);

            if (!string.IsNullOrEmpty(TSReaction.UserID))
            {
                if (userName.Equals("demouser"))
                {
                    return(new TSReaction());
                }
            }

            TSReactionEntity oldReaction = await TS.FindReaction(TSReaction.UserID, true, string.Empty);

            if (oldReaction is null)
            {
                string a = await TS.GetNewID("AllUsers", "LastReactionID", false);

                TSReaction.ReactionID = int.Parse(a);

                bool b = await TS.AddReaction(TSReaction);

                if (b)
                {
                    await GlobalFunctions.NotifyAdmin("New Reaction " + userName + " " + TSReaction.LikeOrDislike);

                    if (TSReaction.LikeOrDislike)
                    {
                        await TS.UpdateSettingCounter("AllUsers", "LikesCount", true);
                    }
                    else
                    {
                        await TS.UpdateSettingCounter("AllUsers", "DislikesCount", true);
                    }
                }
            }
            else
            {
                if (oldReaction.LikeOrDislike != TSReaction.LikeOrDislike)
                {
                    if (oldReaction.LikeOrDislike)
                    {
                        await TS.UpdateSettingCounter("AllUsers", "LikesCount", false);
                    }
                    else
                    {
                        await TS.UpdateSettingCounter("AllUsers", "DislikesCount", false);
                    }



                    bool b = await TS.UpdateReaction(TSReaction);

                    if (b)
                    {
                        await GlobalFunctions.NotifyAdmin("Reaction update to " + TSReaction.LikeOrDislike + " " + userName);

                        if (TSReaction.LikeOrDislike)
                        {
                            await TS.UpdateSettingCounter("AllUsers", "LikesCount", true);
                        }
                        else
                        {
                            await TS.UpdateSettingCounter("AllUsers", "DislikesCount", true);
                        }
                    }
                }
            }


            SymmKeyAndIV ClientSymmKeyAndIV = new SymmKeyAndIV
            {
                Key = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmKey", 5),
                IV  = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmIV", 10)
            };


            if (!string.IsNullOrEmpty(ClientSymmKeyAndIV.Key))
            {
                TSReactionEntity reactionEntity = await TS.FindReaction(TSReaction.UserID, true, string.Empty);

                if (reactionEntity != null)
                {
                    TSReaction result = reactionEntity.toTSReaction();
                    GlobalFunctions.CmdEncryptEntitySymm(result, ClientSymmKeyAndIV);
                    return(result);
                }
                else
                {
                    return(new TSReaction());
                }
            }
            else
            {
                return(new TSReaction());
            }
        }
        public async Task <ActionResult <TSFeedback> > AddFeedback([FromBody] TSFeedback TSFeedback)
        {
            GlobalFunctions.CmdDecryptEntityAsymm(TSFeedback);

            TSFeedback.UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(TSFeedback.UserID, "Add or update Feedback", MethodBase.GetCurrentMethod());

            string userName = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserName", 10);

            if (!string.IsNullOrEmpty(TSFeedback.UserID))
            {
                if (userName.Equals("demouser"))
                {
                    return(new TSFeedback());
                }
            }



            TSFeedbackEntity oldFeedback = await TS.FindFeedback(TSFeedback.UserID, true, string.Empty);

            if (oldFeedback is null)
            {
                string a = await TS.GetNewID("AllUsers", "LastFeedbackID", false);

                TSFeedback.FeedbackID = int.Parse(a);


                bool b = await TS.AddFeedback(TSFeedback);

                if (b)
                {
                    await GlobalFunctions.NotifyAdmin("New Feedback " + userName + " " + TSFeedback.Text);

                    await TS.UpdateSettingCounter("AllUsers", "FeedbackCount", true);
                }
            }
            else
            {
                if (oldFeedback.Text != TSFeedback.Text)
                {
                    bool b = await TS.UpdateFeedback(TSFeedback);

                    if (b)
                    {
                        await GlobalFunctions.NotifyAdmin("Feedback update to " + TSFeedback.Text + " " + userName);
                    }
                }
            }



            SymmKeyAndIV ClientSymmKeyAndIV = new SymmKeyAndIV
            {
                Key = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmKey", 5),
                IV  = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmIV", 10)
            };


            if (!string.IsNullOrEmpty(ClientSymmKeyAndIV.Key))
            {
                TSFeedbackEntity feedbackEntity = await TS.FindFeedback(TSFeedback.UserID, true, string.Empty);

                if (feedbackEntity != null)
                {
                    TSFeedback result = feedbackEntity.toTSFeedback();
                    GlobalFunctions.CmdEncryptEntitySymm(result, ClientSymmKeyAndIV);
                    return(result);
                }
                else
                {
                    return(new TSFeedback());
                }
            }
            else
            {
                return(new TSFeedback());
            }
        }
Beispiel #13
0
 public static string CmdSymmetricDecrypt(string cipherText, SymmKeyAndIV ParSymmKeyAndIV)
 {
     return(CmdSymmetricDecrypt(Convert.FromBase64String(cipherText), Convert.FromBase64String(ParSymmKeyAndIV.Key), Convert.FromBase64String(ParSymmKeyAndIV.IV)));
 }
Beispiel #14
0
 public static string CmdSymmetricEncrypt(string plainText, SymmKeyAndIV ParSymmKeyAndIV)
 {
     return(Convert.ToBase64String(CmdSymmetricEncrypt(plainText, Convert.FromBase64String(ParSymmKeyAndIV.Key), Convert.FromBase64String(ParSymmKeyAndIV.IV))));
 }