Ejemplo n.º 1
0
        public void ShouldConvertDateTimeToUnixTimestamp()
        {
            var psk = new Psk {
                Hash = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff"
            };

            psk.IsEqualTo("ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff").Should().BeTrue();
        }
        public bool IsAuthorized(AuthorizationFilterContext context, Psk psk)
        {
            using (var algorithm = psk.Algorithm)
            {
                var hash = algorithm.ComputeHash(Encoding.Default.GetBytes(_options.Secret + _options.Salt));
                algorithm.Clear();

                return(psk.IsEqualTo(Convert.ToBase64String(hash)));
            }
        }
Ejemplo n.º 3
0
        public void ShouldConvertDateTimeToUnixTimestamp()
        {
            var psk = new Psk
            {
                Algorithm = SHA512.Create(),
                Hash      = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff",
                Timestamp = DateTime.UtcNow.ToUnix()
            };

            psk.Timestamp.Should().Be(DateTime.UtcNow.ToUnix());
        }
Ejemplo n.º 4
0
 public static bool IsEqualTo(this Psk psk, string hash)
 {
     return(psk.Hash == hash);
 }