public static async Task <string> SignJwt(this string contentJson, IDigitalSigner digitalSigner) { var jwt = EncodeJwtFromJson(contentJson); var rawDataBytes = Encoding.UTF8.GetBytes(jwt); var digest = rawDataBytes.ToSha256(); var signature = await digitalSigner.SignAsync(SecurityAlgorithms.RsaSha256, digest); var encodedSignature = Base64UrlEncoder.Encode(signature); return(jwt + "." + encodedSignature); }
public async Task <string> GenerateToken(JwtHeader header, JwtPayload payload) { var jwtSecurityToken = new JwtSecurityToken(header, payload); var rawDataBytes = System.Text.Encoding.UTF8.GetBytes(jwtSecurityToken.EncodedHeader + "." + jwtSecurityToken.EncodedPayload); var digest = rawDataBytes.ToSha256(); var signature = await _sign.SignAsync(SecurityAlgorithms.RsaSha256, digest); var encodedSignature = Base64UrlEncoder.Encode(signature); return(jwtSecurityToken.EncodedHeader + "." + jwtSecurityToken.EncodedPayload + "." + encodedSignature); }