Example #1
0
 void ValidateNonce(ProtectedHeader protectedHeader)
 {
     if (!_nonceMgr.ValidateNonce(protectedHeader.Nonce))
     {
         throw new Exception("Bad Nonce");
     }
 }
Example #2
0
 private string GetSigningInput()
 {
     return(Encoding.ASCII.GetBytes(
                Base64UrlEncode(Encoding.UTF8.GetBytes(ProtectedHeader.ToString())))
            + "."
            + Base64UrlEncode(Encoding.UTF8.GetBytes(Payload)));
 }
Example #3
0
        public void Verify()
        {
            try
            {
                var validationResults = new List <IComputationError>();
                var parts             = GetParts();
                foreach (var prop in ProtectedHeader.Properties())
                {
                    switch (prop.Name)
                    {
                    case "alg":
                        ALGVerifySignature(prop.Value <string>(), parts);
                        break;

                    default:
                        throw new JsonWebSignatureException($"\"{prop.Name}\" Header Parameter has not been implemented.");
                    }
                }

                throw new JsonWebSignatureException("The JWS signature MUST use an algorithm of \"RS256\", \"RS384\", or \"RS512\".");
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #4
0
 public string SerializeCompact()
 {
     return(string.Join(".", new string[] {
         Base64UrlEncode(Encoding.UTF8.GetBytes(ProtectedHeader.ToString())),
         Base64UrlEncode(Encoding.UTF8.GetBytes(Payload)),
         Base64UrlEncode(Encoding.ASCII.GetBytes(Signature))
     }));
 }
Example #5
0
        public string[] GetParts()
        {
            string encodedProtectedHeader = Base64UrlEncode(Encoding.UTF8.GetBytes(ProtectedHeader.ToString()));
            string payload   = Base64UrlEncode(Encoding.UTF8.GetBytes(Payload));
            string signature = Base64UrlEncode(Encoding.ASCII.GetBytes(Signature));

            return(new string[] { encodedProtectedHeader, payload, signature });
        }