Git Product home page Git Product logo

Comments (1)

drew-fc avatar drew-fc commented on June 5, 2024

Got it working, big thanks to @abatishchev .

Here's the snippet if you need to get this working with RSA. Obviously this key pair is not real, and you should never save a keypair directly into your code. This is helpful for the example though since there's so many possible formats of RSA keys.

 public static string IssueJwtWithKeysOnly(Dictionary<string,object> claims)
        {
        //         var pub = @"-----BEGIN PUBLIC KEY-----
        //         MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDTGvumTtnGD5S+xw6oH3LOuysp
        //         j6s4KDo6fsbGGAzp8Jb2PBRd/Ree0+FtzNQoVaDka2uCocnuX8+YTpv6J7zDN0zB
        //         YWuqBmQVW+5FTjPGkdKwgchzTGLdPtzdUllgqkaDdogBCcyBq6cnDT2U5q1p1j5e
        //         +Pnzt4gXGnBoETBzpwIDAQAB
        //         -----END PUBLIC KEY-----";

        //             var priv = @"-----BEGIN RSA PRIVATE KEY-----
        // MIICXwIBAAKBgQDTGvumTtnGD5S+xw6oH3LOuyspj6s4KDo6fsbGGAzp8Jb2PBRd
        // /Ree0+FtzNQoVaDka2uCocnuX8+YTpv6J7zDN0zBYWuqBmQVW+5FTjPGkdKwgchz
        // TGLdPtzdUllgqkaDdogBCcyBq6cnDT2U5q1p1j5e+Pnzt4gXGnBoETBzpwIDAQAB
        // AoGBAIIGhqWCv6O8iROQq7hl1mL66bTppr4qGONanrf4rEuTQohbrPfPIbNUMe9d
        // T/ef9j964ndNi4DlRoo7MNs9iodcqX8KMnNXOlV9iBi+7mpe8jmHC5ZGAoTGnPt5
        // vNXPAGtWbSuan8dDkFbbAikmtzIUJdlhj60sU9Q7vpYacI6xAkEA7BcCDQ8JyQNg
        // gSKgyyN5T/Rzdj68B1JOVvZtVoQLtyf84XK4E4uUTJ2U+3FNr0FtCV3qK7B6IQbv
        // QfOMzbsBRQJBAOTolIXvE+Gci3SDyU0zRp1uAggEdnUX/6vul7fLcPT0+9COD7H6
        // 2WKxYGDDAVXI9KyO/YNe+DYwYXi0wW64MfsCQQCN9ofVMmW/6bft7tShUgNwgJ2t
        // TKvj+yoAQM4eZ+hjijgVmNX3ascSCu+7Araj28OlDkPxYX0Ovwy/q6PPUdPBAkEA
        // 4jK2OZdjhQkFgVCNBj2KJR1E4plOWS0q18JAqD1f1J+ViqQm/FAOqoju3Q817YhT
        // x4TRHRUmn521Y+ryTi+0KwJBAK4D7P7sKAiUYS/Q9TXv1KqW76Vv8JaPDSkhu8bW
        // JYmM7mkwoUEEkV7v4Zkp74rmiG+9wmOxBsAjEcHl/IC7Pac=
        // -----END RSA PRIVATE KEY-----";

            var pubRSA = RSA.Create();
            pubRSA.ImportFromPem(pub);


            var privRSA = RSA.Create();
            privRSA.ImportFromPem(priv);

           string token = JwtBuilder.Create()
                                 .WithAlgorithm(new RS256Algorithm(pubRSA,privRSA)).AddClaims(claims).Encode();

            return token;
        }

from jwt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.