コード例 #1
0
        public void MachineKeyEncryptionTest1()
        {
            const string data      = "Some text to encrypt";
            var          encrypted = MachineKeyEncryption.Encode(data);
            var          decrypted = MachineKeyEncryption.Decode(encrypted);

            Assert.AreEqual(data, decrypted);
        }
コード例 #2
0
        public string Encode(string plainValue, bool urlEncode = false)
        {
            var encodedValue = string.Empty;

            try
            {
                encodedValue = MachineKeyEncryption.Encode(plainValue);
            }
            catch
            {
                _logManager.LogError($"Error trying to encode {plainValue}", GetType());
                return(encodedValue);
            }

            if (urlEncode)
            {
                return(HttpUtility.UrlEncode(encodedValue));
            }

            return(encodedValue);
        }
コード例 #3
0
        /// <summary>
        /// Writes the cookie.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="value">The value.</param>
        public static void WriteCookie(string name, string value)
        {
            Assert.ArgumentNotNull(name, "name");
            Assert.ArgumentNotNull(value, "value");

            if (name == WebUtil.GetLoginCookieName())
            {
                value = MachineKeyEncryption.Encode(value);
            }
            HttpContext.Current.Response.AppendCookie(new HttpCookie(name, value)
            {
                Expires = DateTime.Now.AddMonths(3),
                Path    = "/sitecore/login"
            });
            var httpCookie = HttpContext.Current.Request.Cookies[name];

            if (httpCookie == null)
            {
                return;
            }

            httpCookie.Value = value;
        }
コード例 #4
0
        public string TokenEncoder(string token, TimeSpan lifetime)
        {
            token = MachineKeyEncryption.Encode(token + "^" + (DateTime.UtcNow + lifetime).Ticks);

            return(HttpServerUtility.UrlTokenEncode(Encoding.UTF8.GetBytes(token)));
        }