Exemple #1
0
 private void DecryptNotes(List <NoteModel> modelNotes)
 {
     modelNotes.ForEach(x =>
     {
         x.Content = EncryptionUtil.Decrypt(x.Content);
     });
 }
Exemple #2
0
        public void TestDecryptInvalidByteArray()
        {
            byte[] notParent = new byte[] { 1, 3, 4, 6, 8 };

            Parent decryptedParent = (Parent)EncryptionUtil.Decrypt(notParent);

            Assert.Null(decryptedParent);
        }
Exemple #3
0
        public void TestEncryptionBoundary()
        {
            Assert.Null(EncryptionUtil.Encrypt(""));
            Assert.Null(EncryptionUtil.Decrypt(""));

            Assert.Null(EncryptionUtil.Encrypt(null));
            Assert.Null(EncryptionUtil.Decrypt((byte[])null));
        }
Exemple #4
0
        /// <summary>
        /// 通过编号获取用户信息
        /// </summary>
        /// <param name="id">用户编号</param>
        /// <returns>用户信息</returns>
        public UserInfo GetUser(int id)
        {
            UserInfo info = this.userDao.GetUser(id);

            if (info != null && !string.IsNullOrEmpty(info.LoginPwd))
            {
                info.LoginPwd = EncryptionUtil.Decrypt(info.LoginPwd);
            }
            return(info);
        }
Exemple #5
0
        public void TestEncryptStringInstance()
        {
            string encryptedHello = EncryptionUtil.Encrypt("hello");

            Assert.NotNull(encryptedHello);
            Assert.AreEqual("5ow9IiHrgxf70OPplWItuQ==", encryptedHello);

            string decryptedHello = EncryptionUtil.Decrypt(encryptedHello);

            Assert.AreEqual("hello", decryptedHello);
        }
        public void CompleteExample()
        {
            var          mySecretText         = "This is my secret";
            const string completeExampleAlias = "CompleteExample";
            var          encryptedBundle      = EncryptionUtil.Encrypt(context, completeExampleAlias, mySecretText);

            Assert.False(mySecretText == encryptedBundle.EncryptedText);

            var decryptedText = EncryptionUtil.Decrypt(context, completeExampleAlias, encryptedBundle);

            Assert.True(mySecretText == decryptedText,
                        string.Format("Expect {0} but got {1}", mySecretText, decryptedText));
        }
Exemple #7
0
        /// <summary>
        /// 通过用户名获取用户信息
        /// </summary>
        /// <param name="loginID">用户名</param>
        /// <returns>用户信息</returns>
        public UserInfo GetUserByLoginID(string loginID)
        {
            UserInfo info = this.userDao.GetUserByLoginID(loginID);

            if (info != null)
            {
                if (!string.IsNullOrEmpty(info.LoginPwd))
                {
                    info.LoginPwd = EncryptionUtil.Decrypt(info.LoginPwd);
                }
            }

            return(info);
        }
Exemple #8
0
        public void TestDecryptValidEncryptedByteArray()
        {
            Parent parent = new Parent {
                Name = "Hello", Child = new Child {
                    Name = "World"
                }
            };

            byte[] encryptedParent = EncryptionUtil.Encrypt(parent);

            Parent decryptedParent = (Parent)EncryptionUtil.Decrypt(encryptedParent);

            Assert.NotNull(decryptedParent);
            Assert.AreEqual("Hello", decryptedParent.Name);
            Assert.AreEqual("World", decryptedParent.Child.Name);
        }
Exemple #9
0
 /// <summary>
 /// 获取token
 /// </summary>
 /// <returns>解密后密码</returns>
 public string CheckToken()
 {
     try
     {
         string token = Request.QueryString["token"];
         if (!string.IsNullOrEmpty(token))
         {
             return(EncryptionUtil.Decrypt(token));
         }
     }
     catch (Exception ex)
     {
         NLog.LogManager.GetCurrentClassLogger().Error(ex, ex.Message);
     }
     return(null);
 }
Exemple #10
0
        public JsonResult UpdateUserInfo(UserInfo info, string sessionID)
        {
            ServiceResultModel <UserInfo> response = new ServiceResultModel <UserInfo>();

            UserInfo user = new UserInfo();

            try
            {
                if (!CheckSessionID(info.ID, sessionID, response))
                {
                    return(MyJson(response, JsonRequestBehavior.AllowGet));
                }
                if (CheckUser(info.ID, response, out user) == false)
                {
                    return(MyJson(response, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    if (info.LoginPwd == "" || info.LoginPwd == null)
                    {
                        info.LoginPwd = EncryptionUtil.Decrypt(user.LoginPwd);
                    }

                    info.IsActive     = user.IsActive;
                    info.VerifyStatus = user.VerifyStatus;
                    info.Role         = user.Role;
                    info.LoginID      = user.LoginID;
                    info.Comments     = user.Comments;

                    this.userManager.SaveUser(info);

                    response.Data = info;
                }
            }
            catch (Exception ex)
            {
                NLog.LogManager.GetCurrentClassLogger().Error(ex, ex.Message);
                response.SetFailed(ResultCodes.SystemError, ControlManager.GetSettingInfo().ErrorMessage);
            }

            return(MyJson(response, JsonRequestBehavior.AllowGet));
        }
Exemple #11
0
        public override void up(Event evt)
        {
            Message msg, rsp_msg;

            System.Object obj;
            PingHeader    hdr, rsp_hdr;
            PingRsp       rsp;
            Address       coord;

            switch (evt.Type)
            {
            case Event.MSG:
                msg = (Message)evt.Arg;

                obj = msg.getHeader(HeaderType.TCPPING);
                if (obj == null || !(obj is PingHeader))
                {
                    passUp(evt);
                    return;
                }

                hdr = (PingHeader)msg.removeHeader(HeaderType.TCPPING);

                switch (hdr.type)
                {
                case PingHeader.GET_MBRS_REQ:          // return Rsp(local_addr, coord)

                    if (!hdr.group_addr.Equals(group_addr))
                    {
                        if (Stack.NCacheLog.IsInfoEnabled)
                        {
                            Stack.NCacheLog.Info("TcpPing.up()", "GET_MBRS_REQ from different group , so discarded");
                        }
                        return;
                    }
                    Address src = (Address)hdr.arg;
                    msg.Src = src;

                    if (Stack.NCacheLog.IsInfoEnabled)
                    {
                        Stack.NCacheLog.Info("TCPPING.up()", "GET_MBRS_REQ from " + msg.Src.ToString());
                    }


                    //determine whether security is required at this level.
                    //we require security only in case of inproc initialization of cache.
                    bool   authorized = true;
                    byte[] secureUid  = hdr.userId;
                    byte[] securePwd  = hdr.password;
                    string uid        = EncryptionUtil.Decrypt(secureUid);
                    string pwd        = EncryptionUtil.Decrypt(securePwd);
                    if (Stack.NCacheLog.IsInfoEnabled)
                    {
                        Stack.NCacheLog.Info("TCPPING.up()", " before authorizing. I have received these credentials user-id = " + userId + ", password = "******"TCPPING.up()", "responding to GET_MBRS_REQ back to " + msg.Src.ToString() + " with empty response");
                        }
                        if (Stack.NCacheLog.IsInfoEnabled)
                        {
                            Stack.NCacheLog.Info("TCPPING.up()", "some un-authorized user has tried to connect to the cluster");
                        }
                        passDown(new Event(Event.MSG, rsp_msg, Priority.High));
                    }
                    else
                    {
                        lock (members.SyncRoot)
                        {
                            coord = members.Count > 0 ? (Address)members[0] : local_addr;
                        }
                        if (Stack.NCacheLog.IsInfoEnabled)
                        {
                            Stack.NCacheLog.Info("TCPPING.up()", "my coordinator is " + coord.ToString());
                        }

                        rsp_msg = new Message(msg.Src, null, null);
                        rsp_hdr = new PingHeader(PingHeader.GET_MBRS_RSP, new PingRsp(local_addr, coord, Stack.IsOperational, Stack.IsOperational));
                        rsp_msg.putHeader(HeaderType.TCPPING, rsp_hdr);
                        if (Stack.NCacheLog.IsInfoEnabled)
                        {
                            Stack.NCacheLog.Info("TCPPING.up()", "responding to GET_MBRS_REQ back to " + msg.Src.ToString());
                        }

                        if (Stack.NCacheLog.IsInfoEnabled)
                        {
                            Stack.NCacheLog.Info(local_addr + " - [FIND_INITIAL_MBRS] replying PING request to " + rsp_msg.Dest);
                        }

                        passDown(new Event(Event.MSG, rsp_msg, Priority.High));
                    }
                    return;

                case PingHeader.GET_MBRS_RSP:          // add response to vector and notify waiting thread
                    if (Stack.NCacheLog.IsInfoEnabled)
                    {
                        Stack.NCacheLog.Info("TCPPING.up()", "GET_MBRS_RSP from " + msg.Src.ToString());
                    }
                    rsp = (PingRsp)hdr.arg;


                    //check if the received response is valid i.e. successful security authorization
                    //at other end.
                    if (rsp.OwnAddress == null && rsp.CoordAddress == null && rsp.HasJoined == false)
                    {
                        lock (initial_members.SyncRoot)
                        {
                            if (Stack.NCacheLog.IsInfoEnabled)
                            {
                                Stack.NCacheLog.Info("TCPPING.up()", "I am not authorized to join to " + msg.Src.ToString());
                            }
                            System.Threading.Monitor.PulseAll(initial_members.SyncRoot);
                        }
                    }
                    else
                    {
                        if (Stack.NCacheLog.IsInfoEnabled)
                        {
                            Stack.NCacheLog.Info("TCPPING.up()", "Before Adding initial members response");
                        }
                        lock (initial_members.SyncRoot)
                        {
                            if (Stack.NCacheLog.IsInfoEnabled)
                            {
                                Stack.NCacheLog.Info("TCPPING.up()", "Adding initial members response");
                            }
                            if (!initial_members.Contains(rsp))
                            {
                                initial_members.Add(rsp);
                                if (Stack.NCacheLog.IsInfoEnabled)
                                {
                                    Stack.NCacheLog.Info("TCPPING.up()", "Adding initial members response for " + rsp.OwnAddress);
                                }
                            }
                            else
                            if (Stack.NCacheLog.IsInfoEnabled)
                            {
                                Stack.NCacheLog.Info("TcpPing.up()", "response already received");
                            }
                            System.Threading.Monitor.PulseAll(initial_members.SyncRoot);
                        }
                    }
                    return;

                default:
                    Stack.NCacheLog.Warn("got TCPPING header with unknown type (" + hdr.type + ')');
                    return;
                }

            case Event.SET_LOCAL_ADDRESS:
                passUp(evt);
                local_addr = (Address)evt.Arg;
                // Add own address to initial_hosts if not present: we must always be able to ping ourself !
                if (initial_hosts != null && local_addr != null)
                {
                    if (!initial_hosts.Contains(local_addr))
                    {
                        Stack.NCacheLog.Debug("[SET_LOCAL_ADDRESS]: adding my own address (" + local_addr + ") to initial_hosts; initial_hosts=" + Global.CollectionToString(initial_hosts));
                        initial_hosts.Add(local_addr);
                    }
                }
                break;

            case Event.CONNECT_OK:
                obj = evt.Arg;

                if (obj != null && obj is Address)
                {
                    tcpServerPort = ((Address)obj).Port;
                }
                passUp(evt);
                break;

            case Event.CONNECTION_NOT_OPENED:
                if (mbrDiscoveryInProcess)
                {
                    Address node     = evt.Arg as Address;
                    PingRsp response = new PingRsp(node, node, true, false);
                    lock (initial_members.SyncRoot)
                    {
                        initial_members.Add(response);
                        System.Threading.Monitor.PulseAll(initial_members.SyncRoot);
                    }
                    if (Stack != null && Stack.NCacheLog != null && Stack.NCacheLog.IsDebugEnabled)
                    {
                        Stack.NCacheLog.Debug(Name + ".up", "connection failure with " + node);
                    }
                }

                break;

            // end services
            default:
                passUp(evt);     // Pass up to the layer above us
                break;
            }
        }