public void CreateTest() { var date = new DateTime(2019, 1, 2, 12, 0, 0); var mils = date.ToUnix(); var from = DateTimeExt.FromUnix(mils); Assert.AreEqual(from, date.ToUniversalTime()); }
public IResultMonad <T> DecodeToken <T>(byte[] value) { var valueSpan = new Span <byte>(value); var token = valueSpan.Slice(0, TOKEN_LENGTH); var compareToken = SecurityHelpers.Hmac512( _sharedSecret, value, TOKEN_LENGTH, value.Length - TOKEN_LENGTH); if (compareToken.SpanByteCompare(token)) { var currentDate = DateTime.Now.ToUniversalTime(); var expires = DateTimeExt.FromUnix(BitConverter.ToInt64(valueSpan.Slice(EXPIRE_DATE_START, EXPIRE_DATE_LENGTH))); if (currentDate < expires) { var bodyS = valueSpan.Slice(BODY_START); var json = Encoding.UTF8.GetString(bodyS); return(JsonHelper.Decode <T>(json).ToResultMonad()); } else { return(new ResultError <T>(new List <string> { "Token has expired." })); } } else { return(new ResultError <T>(new List <string> { "The tokens do not match." })); } }