<commit_before>﻿using System;
using System.Linq;
using System.Security.Cryptography;
using Microsoft.IdentityModel.JsonWebTokens;
using Microsoft.IdentityModel.Tokens;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Crypto.Signers;
using Org.BouncyCastle.Math;

namespace ScottBrady91.BlogExampleCode.CustomJwtAlgorithm
{
    public class Program
    {
        public static void Main()
        {
            X9ECParameters secp256k1 = ECNamedCurveTable.GetByName("secp256k1");
            ECDomainParameters domainParams = new ECDomainParameters(secp256k1.Curve, secp256k1.G, secp256k1.N, secp256k1.H, secp256k1.GetSeed());

            var point = secp256k1.Curve.CreatePoint(
                new BigInteger(1, Base64UrlEncoder.DecodeBytes("A3hkIubgDggcoHzmVdXIm11gZ7UMaOa71JVf1eCifD8")),
                new BigInteger(1, Base64UrlEncoder.DecodeBytes("ejpRwmCvNMdXMOjR2DodOt09OLPgNUrcKA9hBslaFU0")));
            
            var handler = new JsonWebTokenHandler();

            var token = handler.CreateToken(new SecurityTokenDescriptor
            {
                Issuer = "me",
                Audience = "you",
                SigningCredentials = new SigningCredentials(new BouncyCastleEcdsaSecurityKey(
                    new ECPrivateKeyParameters(new BigInteger(1, Base64UrlEncoder.DecodeBytes("e8HThqO0wR_Qw4pNIb80Cs0mYuCSqT6BSQj-o-tKTrg")), domainParams)), "ES256K")
            });
            Console.WriteLine(token);

             var result = handler.ValidateToken(
                token,
                new TokenValidationParameters
                {
                    ValidIssuer = "me",
                    ValidAudience = "you",
                    IssuerSigningKey = new BouncyCastleEcdsaSecurityKey(
                        new ECPublicKeyParameters(point, domainParams)) {KeyId = "123"}
                });
<commit_msg>Final custom JWT updates for article<commit_after>﻿using System;
using System.Linq;
using System.Security.Cryptography;
using Microsoft.IdentityModel.JsonWebTokens;
using Microsoft.IdentityModel.Tokens;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Crypto.Signers;
using Org.BouncyCastle.Math;

namespace ScottBrady91.BlogExampleCode.CustomJwtAlgorithm
{
    public class Program
    {
        public static void Main()
        {
            X9ECParameters secp256k1 = ECNamedCurveTable.GetByName("secp256k1");
            ECDomainParameters domainParams = new ECDomainParameters(secp256k1.Curve, secp256k1.G, secp256k1.N, secp256k1.H, secp256k1.GetSeed());

            const string d = "<KEY>";
            const string x = "<KEY>";
            const string y = "<KEY>";

            var point = secp256k1.Curve.CreatePoint(
                new BigInteger(1, Base64UrlEncoder.DecodeBytes(x)),
                new BigInteger(1, Base64UrlEncoder.DecodeBytes(y)));
            
            var handler = new JsonWebTokenHandler();

            var token = handler.CreateToken(new SecurityTokenDescriptor
            {
                Issuer = "me",
                Audience = "you",
                SigningCredentials = new SigningCredentials(new BouncyCastleEcdsaSecurityKey(
                    new ECPrivateKeyParameters(new BigInteger(1, Base64UrlEncoder.DecodeBytes(d)), domainParams)) {KeyId = "123"}, "ES256K")
            });
            Console.WriteLine(token);

             var result = handler.ValidateToken(
                token,
                new TokenValidationParameters
                {
                    ValidIssuer = "me",
                    ValidAudience = "you",
                    IssuerSigningKey = new BouncyCastleEcdsaSecurityKey(
                        new ECPublicKeyParameters(point, domainParams)) {KeyId = "123"}
                });

{'fraction_non_alphanumeric': 0.08446652719665272, 'fraction_numerical': 0.03321129707112971, 'mean_word_length': 2.3464566929133857, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3282656', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1121, 'n_words': 195}