.net 加密的激活链接,数据合并在URL中

.net 加密的激活链接,数据合并在URL中,.net,asp.net-mvc,.net,Asp.net Mvc,加密的激活链接,数据合并在URL中 我有下面的函数进行加密和解密,这是正确的方法吗 public static string GenerateActivationLink(int userId, long invitedId) { byte[] bytes; using (var ms = new MemoryStream()) using (var bw = new BinaryWriter(ms))

加密的激活链接,数据合并在URL中 我有下面的函数进行加密和解密,这是正确的方法吗

public static string GenerateActivationLink(int userId, long invitedId)
        {
            byte[] bytes;
            using (var ms = new MemoryStream())
            using (var bw = new BinaryWriter(ms))
            {
                bw.Write(DateTime.UtcNow.AddHours(3).ToBinary());
                bw.Write(userId);
                bw.Write(invitedId);
                bw.Flush();
                bytes = ms.ToArray();
            }
            var token = Convert.ToBase64String(MachineKey.Protect(bytes, "Activate"));

            var externalUrl = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);

            var activateLink = UriHelper.Combine(externalUrl, "Account/Activate?t=");
            activateLink = activateLink + Uri.EscapeDataString(token);
            return activateLink;
        }


Decryption

 //Decripted link
        public ActionResult Login(string t)
        {
            var token = Uri.UnescapeDataString(t);

            string apiKey="";// = "uu5acvv";
            Int32 userId = 0;// = 30;
            Int64 orderId = 0;// = 12345;  

            try
            {
                var tt = Convert.FromBase64String(token);
                var bytes = MachineKey.Unprotect(tt, "Activate");
                using (var ms = new MemoryStream(bytes))
                using (var br = new BinaryReader(ms))
                {
                    apiKey = br.ReadString();
                    userId = br.ReadInt32();
                    orderId = br.ReadInt64();
                }
            }
            catch (Exception ex)
            {
                //return Error(Texts.Validation.InvalidActivateToken);
            }

            return RedirectToAction("GetOrderCustomerPaymentDetails", new { apiKey = apiKey, userId= userId, orderId = orderId });
            //return RedirectToAction("GetOrderCustomerPaymentDetails" + "?apiKey=" + apiKey + "&userId=" + userId + "&orderId=" + orderId);
        }


加密的激活链接,数据合并在URL中 我有下面的函数进行加密和解密,这是正确的方法吗

public static string GenerateActivationLink(int userId, long invitedId)
        {
            byte[] bytes;
            using (var ms = new MemoryStream())
            using (var bw = new BinaryWriter(ms))
            {
                bw.Write(DateTime.UtcNow.AddHours(3).ToBinary());
                bw.Write(userId);
                bw.Write(invitedId);
                bw.Flush();
                bytes = ms.ToArray();
            }
            var token = Convert.ToBase64String(MachineKey.Protect(bytes, "Activate"));

            var externalUrl = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);

            var activateLink = UriHelper.Combine(externalUrl, "Account/Activate?t=");
            activateLink = activateLink + Uri.EscapeDataString(token);
            return activateLink;
        }


Decryption

 //Decripted link
        public ActionResult Login(string t)
        {
            var token = Uri.UnescapeDataString(t);

            string apiKey="";// = "uu5acvv";
            Int32 userId = 0;// = 30;
            Int64 orderId = 0;// = 12345;  

            try
            {
                var tt = Convert.FromBase64String(token);
                var bytes = MachineKey.Unprotect(tt, "Activate");
                using (var ms = new MemoryStream(bytes))
                using (var br = new BinaryReader(ms))
                {
                    apiKey = br.ReadString();
                    userId = br.ReadInt32();
                    orderId = br.ReadInt64();
                }
            }
            catch (Exception ex)
            {
                //return Error(Texts.Validation.InvalidActivateToken);
            }

            return RedirectToAction("GetOrderCustomerPaymentDetails", new { apiKey = apiKey, userId= userId, orderId = orderId });
            //return RedirectToAction("GetOrderCustomerPaymentDetails" + "?apiKey=" + apiKey + "&userId=" + userId + "&orderId=" + orderId);
        }