Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }