public void A2()
        {
            const string TOKEN = ""
                                 + "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0"
                                 + "."
                                 + "UGhIOguC7IuEvf_NPVaXsGMoLOmwvc1GyqlIKOK1nN94nHPoltGRhWhw7Zx0-kFm"
                                 + "1NJn8LE9XShH59_i8J0PH5ZZyNfGy2xGdULU7sHNF6Gp2vPLgNZ__deLKxGHZ7Pc"
                                 + "HALUzoOegEI-8E66jX2E4zyJKx-YxzZIItRzC5hlRirb6Y5Cl_p-ko3YvkkysZIF"
                                 + "NPccxRU7qve1WYPxqbb2Yw8kZqa2rMWI5ng8OtvzlV7elprCbuPhcCdZ6XDP0_F8"
                                 + "rkXds2vE4X-ncOIM8hAYHHi29NX0mcKiRaD0-D-ljQTP-cFPgwCp6X-nZZd9OHBv"
                                 + "-B3oWh2TbqmScqXMR4gp_A"
                                 + "."
                                 + "AxY8DCtDaGlsbGljb3RoZQ"
                                 + "."
                                 + "KDlTtXchhZTGufMYmOYGS4HffxPSUrfmqCHXaI9wOGY"
                                 + "."
                                 + "9hH0vgRfYgPnAHOd8stkvw";
            string json = this.GetResource("RFC7516_A2.json");

            Assert.NotNull(json);
            var jwk = JWK.Parse(json);

            Assert.NotNull(jwk);
            var s = JWT.Decode(TOKEN, jwk.Key);

            Assert.Equal("Live long and prosper.", s);
        }
        public void A1()
        {
            const string TOKEN = ""
                                 + "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0"
                                 + "."
                                 + "QR1Owv2ug2WyPBnbQrRARTeEk9kDO2w8qDcjiHnSJflSdv1iNqhWXaKH4MqAkQtM"
                                 + "oNfABIPJaZm0HaA415sv3aeuBWnD8J-Ui7Ah6cWafs3ZwwFKDFUUsWHSK-IPKxLG"
                                 + "TkND09XyjORj_CHAgOPJ-Sd8ONQRnJvWn_hXV1BNMHzUjPyYwEsRhDhzjAD26ima"
                                 + "sOTsgruobpYGoQcXUwFDn7moXPRfDE8-NoQX7N7ZYMmpUDkR-Cx9obNGwJQ3nM52"
                                 + "YCitxoQVPzjbl7WBuB7AohdBoZOdZ24WlN1lVIeh8v1K4krB8xgKvRU8kgFrEn_a"
                                 + "1rZgN5TiysnmzTROF869lQ"
                                 + "."
                                 + "AxY8DCtDaGlsbGljb3RoZQ"
                                 + "."
                                 + "MKOle7UQrG6nSxTLX6Mqwt0orbHvAKeWnDYvpIAeZ72deHxz3roJDXQyhxx0wKaM"
                                 + "HDjUEOKIwrtkHthpqEanSBNYHZgmNOV7sln1Eu9g3J8"
                                 + "."
                                 + "fiK51VwhsxJ-siBMR-YFiA";
            const string PAYLOAD = ""
                                   + "eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt"
                                   + "cGxlLmNvbS9pc19yb290Ijp0cnVlfQ";
            string json = Helpers.ReadResource(typeof(RFC7516_A_JWE_Examples), "RFC7516_A2.json");

            Assert.NotNull(json);
            var jwk = JWK.Parse(json);

            Assert.NotNull(jwk);
            var s = JWT.Decode(TOKEN, jwk.Key);

            Assert.Equal(Encoding.UTF8.GetString(Base64Url.Decode(PAYLOAD)), s);
        }
        public void A1()
        {
            const string TOKEN = ""
                                 + "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ"
                                 + "."
                                 + "OKOawDo13gRp2ojaHV7LFpZcgV7T6DVZKTyKOMTYUmKoTCVJRgckCL9kiMT03JGe"
                                 + "ipsEdY3mx_etLbbWSrFr05kLzcSr4qKAq7YN7e9jwQRb23nfa6c9d-StnImGyFDb"
                                 + "Sv04uVuxIp5Zms1gNxKKK2Da14B8S4rzVRltdYwam_lDp5XnZAYpQdb76FdIKLaV"
                                 + "mqgfwX7XWRxv2322i-vDxRfqNzo_tETKzpVLzfiwQyeyPGLBIO56YJ7eObdv0je8"
                                 + "1860ppamavo35UgoRdbYaBcoh9QcfylQr66oc6vFWXRcZ_ZT2LawVCWTIy3brGPi"
                                 + "6UklfCpIMfIjf7iGdXKHzg"
                                 + "."
                                 + "48V1_ALb6US04U3b"
                                 + "."
                                 + "5eym8TW_c8SuK0ltJ3rpYIzOeDQz7TALvtu6UG9oMo4vpzs9tX_EFShS8iB7j6ji"
                                 + "SdiwkIr3ajwQzaBtQD_A"
                                 + "."
                                 + "XFBoMYUZodetZdvTiFvSkQ";
            string json = this.GetResource("RFC7516_A1.json");

            Assert.NotNull(json);
            var jwk = JWK.Parse(json);

            Assert.NotNull(jwk);
            var s = JWT.Decode(TOKEN, jwk.Key);

            Assert.Equal("The true sign of intelligence is not knowledge but imagination.", s);
        }
Exemple #4
0
        public void ImportFails()
        {
            JWK jwk = new JWK()
            {
                Key = JsonWebKeyTest.CreateRSA()
            };

            JWT.Encode("payload", jwk.Key, JwsAlgorithm.RS256);

            var map = JWT.DefaultSettings
                      .JwkAlgorithmFromKey(jwk.Key)
                      .Serialize(jwk, true);

            map.Remove("p");
            map.Remove("q");
            map.Remove("dp");
            map.Remove("dq");
            map.Remove("qi");
            string json = JWT.DefaultSettings
                          .JsonMapper
                          .Serialize(map);

            Console.WriteLine(json);
            jwk = JWK.Parse(json);

            // cannot import RSA private key with only n, e and d
            JWT.Encode("payload", jwk.Key, JwsAlgorithm.RS256);
        }
        public void A2()
        {
            const string TOKEN = ""
                                 + "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiY3R5IjoiSldU"
                                 + "In0"
                                 + "."
                                 + "g_hEwksO1Ax8Qn7HoN-BVeBoa8FXe0kpyk_XdcSmxvcM5_P296JXXtoHISr_DD_M"
                                 + "qewaQSH4dZOQHoUgKLeFly-9RI11TG-_Ge1bZFazBPwKC5lJ6OLANLMd0QSL4fYE"
                                 + "b9ERe-epKYE3xb2jfY1AltHqBO-PM6j23Guj2yDKnFv6WO72tteVzm_2n17SBFvh"
                                 + "DuR9a2nHTE67pe0XGBUS_TK7ecA-iVq5COeVdJR4U4VZGGlxRGPLRHvolVLEHx6D"
                                 + "YyLpw30Ay9R6d68YCLi9FYTq3hIXPK_-dmPlOUlKvPr1GgJzRoeC9G5qCvdcHWsq"
                                 + "JGTO_z3Wfo5zsqwkxruxwA"
                                 + "."
                                 + "UmVkbW9uZCBXQSA5ODA1Mg"
                                 + "."
                                 + "VwHERHPvCNcHHpTjkoigx3_ExK0Qc71RMEParpatm0X_qpg-w8kozSjfNIPPXiTB"
                                 + "BLXR65CIPkFqz4l1Ae9w_uowKiwyi9acgVztAi-pSL8GQSXnaamh9kX1mdh3M_TT"
                                 + "-FZGQFQsFhu0Z72gJKGdfGE-OE7hS1zuBD5oEUfk0Dmb0VzWEzpxxiSSBbBAzP10"
                                 + "l56pPfAtrjEYw-7ygeMkwBl6Z_mLS6w6xUgKlvW6ULmkV-uLC4FUiyKECK4e3WZY"
                                 + "Kw1bpgIqGYsw2v_grHjszJZ-_I5uM-9RA8ycX9KqPRp9gc6pXmoU_-27ATs9XCvr"
                                 + "ZXUtK2902AUzqpeEUJYjWWxSNsS-r1TJ1I-FMJ4XyAiGrfmo9hQPcNBYxPz3GQb2"
                                 + "8Y5CLSQfNgKSGt0A4isp1hBUXBHAndgtcslt7ZoQJaKe_nNJgNliWtWpJ_ebuOpE"
                                 + "l8jdhehdccnRMIwAmU1n7SPkmhIl1HlSOpvcvDfhUN5wuqU955vOBvfkBOh5A11U"
                                 + "zBuo2WlgZ6hYi9-e3w29bR0C2-pp3jbqxEDw3iWaf2dc5b-LnR0FEYXvI_tYk5rd"
                                 + "_J9N0mg0tQ6RbpxNEMNoA9QWk5lgdPvbh9BaO195abQ"
                                 + "."
                                 + "AVO9iT5AV4CzvDJCdhSFlQ";
            const string PAYLOAD = ""
                                   + "eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt"
                                   + "cGxlLmNvbS9pc19yb290Ijp0cnVlfQ";

            // decrypt with key from JWE A2

            string json1 = Helpers.ReadResource(typeof(RFC7516_A_JWE_Examples), "RFC7516_A2.json");

            Assert.NotNull(json1);
            var jwk1 = JWK.Parse(json1);

            Assert.NotNull(jwk1);
            var s1 = JWT.Decode(TOKEN, jwk1.Key);

            // verify signature with key from JWS A2

            string json2 = Helpers.ReadResource(typeof(RFC7515_A_JWS_Examples), "RFC7515_A2.json");

            Assert.NotNull(json2);
            var jwk2 = JWK.Parse(json2);

            Assert.NotNull(jwk2);
            var s2 = JWT.Decode(s1, jwk2.Key);

            Assert.Equal(Encoding.UTF8.GetString(Base64Url.Decode(PAYLOAD)), s2);
        }
        public void A3()
        {
            const string TOKEN = ""
                                 + "eyJhbGciOiJFUzI1NiJ9"
                                 + "."
                                 + "eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt"
                                 + "cGxlLmNvbS9pc19yb290Ijp0cnVlfQ"
                                 + "."
                                 + "DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSA"
                                 + "pmWQxfKTUJqPP3-Kg6NU1Q";
            const string PAYLOAD = ""
                                   + "eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt"
                                   + "cGxlLmNvbS9pc19yb290Ijp0cnVlfQ";
            string json = this.GetResource("RFC7515_A3.json");
            JWK    jwk  = JWK.Parse(json);
            string s    = JWT.Decode(TOKEN, jwk.Key);

            Assert.AreEqual(Encoding.UTF8.GetString(Base64Url.Decode(PAYLOAD)), s);
        }
        public void A3()
        {
            const string TOKEN = ""
                                 + "eyJhbGciOiJBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0"
                                 + "."
                                 + "6KB707dM9YTIgHtLvtgWQ8mKwboJW3of9locizkDTHzBC2IlrT1oOQ"
                                 + "."
                                 + "AxY8DCtDaGlsbGljb3RoZQ"
                                 + "."
                                 + "KDlTtXchhZTGufMYmOYGS4HffxPSUrfmqCHXaI9wOGY"
                                 + "."
                                 + "U0m_YmjN04DJvceFICbCVQ";
            string json = this.GetResource("RFC7516_A3.json");

            Assert.NotNull(json);
            var jwk = JWK.Parse(json);

            Assert.NotNull(jwk);
            var s = JWT.Decode(TOKEN, jwk.Key);

            Assert.Equal("Live long and prosper.", s);
        }
        public void A1()
        {
            const string TOKEN = ""
                                 + "eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9"
                                 + "."
                                 + "eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt"
                                 + "cGxlLmNvbS9pc19yb290Ijp0cnVlfQ"
                                 + "."
                                 + "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk";
            const string PAYLOAD = ""
                                   + "eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt"
                                   + "cGxlLmNvbS9pc19yb290Ijp0cnVlfQ";
            string json = this.GetResource("RFC7515_A1.json");

            Assert.IsNotNull(json);
            JWK jwk = JWK.Parse(json);

            Assert.IsNotNull(jwk);
            string s = JWT.Decode(TOKEN, jwk.Key);

            Assert.AreEqual(Encoding.UTF8.GetString(Base64Url.Decode(PAYLOAD)), s);
        }
        public void A2()
        {
            const string TOKEN = ""
                                 + "eyJhbGciOiJSUzI1NiJ9"
                                 + "."
                                 + "eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt"
                                 + "cGxlLmNvbS9pc19yb290Ijp0cnVlfQ"
                                 + "."
                                 + "cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7"
                                 + "AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4"
                                 + "BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K"
                                 + "0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqv"
                                 + "hJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrB"
                                 + "p0igcN_IoypGlUPQGe77Rw";
            const string PAYLOAD = ""
                                   + "eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt"
                                   + "cGxlLmNvbS9pc19yb290Ijp0cnVlfQ";
            string json = this.GetResource("RFC7515_A2.json");
            JWK    jwk  = JWK.Parse(json);
            string s    = JWT.Decode(TOKEN, jwk.Key);

            Assert.AreEqual(Encoding.UTF8.GetString(Base64Url.Decode(PAYLOAD)), s);
        }