/// <summary>编码用户和有效期得到令牌</summary> /// <param name="user">用户</param> /// <param name="expire">有效期</param> /// <returns></returns> public String Encode(String user, DateTime expire) { if (user.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(user)); } if (expire.Year < 2000) { throw new ArgumentOutOfRangeException(nameof(expire)); } if (Key.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(Key)); } var dt = new DateTime(1970, 1, 1); var secs = (Int32)(expire - dt).TotalSeconds; // 拼接数据并签名 var data = (user + "," + secs).GetBytes(); var sig = DSAHelper.Sign(data, Key); // Base64拼接数据和签名 return(data.ToUrlBase64() + "." + sig.ToUrlBase64()); }
private void btnDSA_Click(Object sender, EventArgs e) { var buf = GetBytes(); var key = rtPass.Text; if (key.Length < 100) { key = DSAHelper.GenerateKey().First(); rtPass.Text = key; } buf = DSAHelper.Sign(buf, key); SetResult(buf); }
private void btnDSA_Click(Object sender, EventArgs e) { var buf = GetBytes(); var key = rtPass.Text; if (key.Length < 100) { key = DSAHelper.GenerateKey().First(); rtPass.Text = key; } buf = DSAHelper.Sign(buf, key); rtResult.Text = buf.ToHex() + Environment.NewLine + Environment.NewLine + buf.ToBase64(); }