public void VerifySignature_WithCorrectValue()
        {
            //Arrange
            string unsignedSessionData = Convert.ToBase64String(sessionValue);
            string signedSessionData   = signatureHelper.CreateSignature(sessionValue);

            //Act
            bool result = signatureHelper.VerifySignature(unsignedSessionData, signedSessionData);

            //Assert
            Assert.True(result);
        }
예제 #2
0
        public void VerifySignature_WithCorrectValue()
        {
            //Arrange
            string unsignedEncodedValue = Convert.ToBase64String(actualValue);
            string signature            = signatureHelper.CreateSignature(actualValue);

            //Act
            bool result = signatureHelper.VerifySignature(unsignedEncodedValue, signature);

            //Assert
            Assert.True(result);
        }
예제 #3
0
        public async Task <byte[]> GetAsync(string key, CancellationToken token = default)
        {
            var sessionData = await _cache.GetAsync(key, token);

            if (sessionData == null || sessionData.Length == 0)
            {
                return(sessionData);
            }

            var signedValue  = Encoding.UTF8.GetString(sessionData).Split(".");
            var encodedValue = signedValue.First();
            var signature    = signedValue.Last();

            var signatureIsValid = _signatureHelper.VerifySignature(encodedValue, signature);

            if (!signatureIsValid)
            {
                throw new Exception("Session Signature is invalid");
            }

            return(Convert.FromBase64String(encodedValue));
        }