Exemplo n.º 1
0
        public void ToBase64Url()
        {
            string str    = "dZWFyTA5YTg0dDM0NF+>==";
            string actual = EncodingExt.ToBase64Url(str);
            string expect = "ZFpXRnlUQTVZVGcwZERNME5_Ris-PT0";

            Assert.AreEqual(expect, actual);
        }
Exemplo n.º 2
0
        public void GetHmacHash()
        {
            string actual  = EncodingExt.ToBase64Url(CryptoExt.GetHmacHash("HMACSHA256", "lys", "salt"));
            string actual2 = EncodingExt.ToBase64Url(CryptoExt.GetHmacHash <HMACSHA256>("lys", "salt"));
            string expect  = "Liof_mjT4Kd1V7I7ItvcTGO3yBezkbN0UVDHXm7m1Vg";

            Assert.AreEqual(expect, actual);
            Assert.AreEqual(expect, actual2);
        }
Exemplo n.º 3
0
        public string Encode(JwtToken token)
        {
            // 基于(提供给客户端的)基础信息编码
            string header  = EncodingExt.ToBase64Url(SerializeExt.ToJson(token.Header));
            string payload = EncodingExt.ToBase64Url(SerializeExt.ToJson(token.Payload));

            // 生成签名
            string signature = EncodingExt.ToBase64Url(ComputeHash(header, payload, token.Salt));

            return($"{header}.{payload}.{signature}");
        }
Exemplo n.º 4
0
        /// <summary>
        /// 创建随机字符串,用于前端密码加密
        /// </summary>
        public string GetSecret(UserDto dto)
        {
            if (dicSecret == null)
            {
                dicSecret = new Dictionary <string, string>();
            }

            string ctx    = DateTime.Now.ToString();
            string result = EncodingExt.ToBase64Url(ctx);

            dicSecret.SafeAdd(dto.UserName, result);

            return(result);
        }