Ejemplo n.º 1
0
        private Tuple <string, string, string> Compact()
        {
            if (this.header == null)
            {
                this.header = new Dictionary <string, object>();
            }

            this.header[JwtHeaderParameters.Type]      = "JWT";
            this.header[JwtHeaderParameters.Algorithm] = this.algorithm;
            var base64UrlEncodedHeader = this.Base64UrlEncode(this.header, Encoding.UTF8);

            var claims = this.claimsBuilder
                         .Build()
                         .ToDictionary();
            var base64UrlEncodedPayload = this.Base64UrlEncode(claims, Encoding.UTF8);

            string base64UrlEncodedDigest = null;

            if (this.signingKey != null)
            {
                var signer = new JwtSigner(this.signingKey);
                base64UrlEncodedDigest = signer.CalculateSignature(base64UrlEncodedHeader, base64UrlEncodedPayload);
            }

            return(new Tuple <string, string, string>(
                       base64UrlEncodedHeader,
                       base64UrlEncodedPayload,
                       base64UrlEncodedDigest));
        }
        public bool IsValid(string base64UrlEncodedHeader, string base64UrlEncodedPayload, string base64UrlEncodedDigest)
        {
            if (string.IsNullOrEmpty(base64UrlEncodedHeader))
            {
                throw new ArgumentNullException(nameof(base64UrlEncodedHeader));
            }

            if (string.IsNullOrEmpty(base64UrlEncodedPayload))
            {
                throw new ArgumentNullException(nameof(base64UrlEncodedPayload));
            }

            if (string.IsNullOrEmpty(base64UrlEncodedDigest))
            {
                throw new ArgumentNullException(nameof(base64UrlEncodedDigest));
            }

            var signer = new JwtSigner(this.signingKey);
            var calculatedSignature = signer.CalculateSignature(base64UrlEncodedHeader, base64UrlEncodedPayload);
            return base64UrlEncodedDigest.Equals(calculatedSignature, StringComparison.Ordinal);
        }
Ejemplo n.º 3
0
        public bool IsValid(string base64UrlEncodedHeader, string base64UrlEncodedPayload, string base64UrlEncodedDigest)
        {
            if (string.IsNullOrEmpty(base64UrlEncodedHeader))
            {
                throw new ArgumentNullException(nameof(base64UrlEncodedHeader));
            }

            if (string.IsNullOrEmpty(base64UrlEncodedPayload))
            {
                throw new ArgumentNullException(nameof(base64UrlEncodedPayload));
            }

            if (string.IsNullOrEmpty(base64UrlEncodedDigest))
            {
                throw new ArgumentNullException(nameof(base64UrlEncodedDigest));
            }

            var signer = new JwtSigner(this.signingKey);
            var calculatedSignature = signer.CalculateSignature(base64UrlEncodedHeader, base64UrlEncodedPayload);

            return(base64UrlEncodedDigest.Equals(calculatedSignature, StringComparison.Ordinal));
        }