title: How to encrypt JWT security token?
body: <p>I need to secure my web-token with signing and encryption. I wrote the next lines of code:</p>
  
  <pre><code>var tokenHandler = new JwtSecurityTokenHandler();
  var tokenDescriptor = new SecurityTokenDescriptor
  {
        Subject = new ClaimsIdentity(new[]
           {
               new Claim(ClaimTypes.Name, owner.Name),
               new Claim(ClaimTypes.Role, owner.RoleClaimType),
               new Claim("custom claim type", "custom content")
           }),
        TokenIssuerName = "self",
        AppliesToAddress = "http://www.example.com",
        Lifetime = new Lifetime(now, now.AddSeconds(60 * 3)),
        EncryptingCredentials = new X509EncryptingCredentials(new X509Certificate2(cert)),
        SigningCredentials = new X509SigningCredentials(cert1)
  };
  var token = (JwtSecurityToken)tokenHandler.CreateToken(tokenDescriptor);            
  var tokenString = tokenHandler.WriteToken(token);
  </code></pre>
  
  <p>So, I am using some certificates, generated with <code>makecert.exe</code>. Then I read token string with another <code>JwtSecurityTokenHandler</code>:</p>
  
  <pre><code>var tokenHandlerDecr = new JwtSecurityTokenHandler();
  var tok = tokenHandlerDecr.ReadToken(tokenString);
  </code></pre>
  
  <p>And token content is not encrypted (I can see json in <code>tok</code> variable under debugger). What am I doing wrong? How to encrypt token data?</p>