/// <summary> /// Returns a <see cref="System.String" /> that represents this instance. /// </summary> /// <returns>A <see cref="System.String" /> that represents this instance.</returns> /// <remarks>Calling this method provides the raw header information of the JSON Web Token.</remarks> public override string ToString() { List <string> header = new List <string>(); header.Add("\"alg\": {0}".FormatWith(JsonConverter.ToString(JsonWebTokenHashAlgorithmConverter.ToString(Algorithm)))); header.Add("\"typ\": {0}".FormatWith(JsonConverter.ToString(Type))); return("{{ {0} }}".FormatWith(header.ToDelimitedString(", "))); }
/// <summary> /// Computes the signature of the JSON Web Token. /// </summary> /// <param name="base64UrlEncodedHeader">The header information of the JSON Web Token; encoded as a Base64 structure usable for transmission on the URL.</param> /// <param name="base64UrlEncodedPayload">The payload information of the JSON Web Token; encoded as a Base64 structure usable for transmission on the URL.</param> /// <param name="algorithm">The <see cref="JsonWebTokenHashAlgorithm"/> to use when signing the JSON Web Token.</param> /// <param name="secret">The secret that is used when signing the JSON Web Token.</param> /// <returns>A <see cref="string"/> that represent the signature of a JSON Web Token.</returns> public string ComputeSignature(string base64UrlEncodedHeader, string base64UrlEncodedPayload, JsonWebTokenHashAlgorithm algorithm, byte[] secret) { ValidateJwtParameters(base64UrlEncodedHeader, base64UrlEncodedPayload, algorithm, secret); return(Tokenize(base64UrlEncodedHeader, base64UrlEncodedPayload).ComputeKeyedHash(secret, o => { o.AlgorithmType = JsonWebTokenHashAlgorithmConverter.ToHmacAlgorithm(algorithm); o.Encoding = Encoding.UTF8; }).ToUrlEncodedBase64()); }