'How to create a Token using alg: A128KW and enc:A128CBC-HS256 in C# with jose-jwt library

I'm totally new in the world of JWT. I'm using the library jose-jwt in C#. I wrote the following code to get the token:

  1. I declared the payload as a Dictionary

  2. I declared the key as a JSON

  3. I encrypted the payload and the secretKey

         var payload = new Dictionary<string, object>()
         {
             { "sub", "[email protected]" },
             { "exp", 1300819380 }
         };
    
         var json = @"{
             ""kty"":""oct"",
             ""use"":""sig"",
             ""k"":""GawgguFyGrWKav7AX4VKUg""
         }";
    
         var secretKey = Jwk.FromJson(json, JWT.DefaultSettings.JsonMapper);
    
    
         string token = Jose.JWT.Encode(payload, secretKey.OctKey(), JweAlgorithm.A128KW, JweEncryption.A128CBC_HS256);
    

I got the following token: eyJhbGciOiJBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.y3NP9hx4zYmLnpab0tDVZNJ2q5aAG6BpUnMhEn11a7z903J4___LtQ.IRgLnbwqjH6m702g4Hn6QA.XCYICPsoG1dVYmEi-Nu0a4w9yzDm9__xDYT1IsxxLaZEa_tSHSJo9Ai2Ym5aN_Sw.bfH7yGqpopEwrT_O1aD1rA

When I try to decode the token on jwt.io I get the following result: jwt.io decoded token image

There's something wrong in the signature (even though I used the same in the code) and the payload is an uncomprensible string with special chars.

Thanks to anyone who will be able to help me.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source