I'm encrypting a token like this:
var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_configuration.GetSection("TokenAuthentication:SecretKey").Value));
var encryptingCredentials = new EncryptingCredentials(signingKey, JwtConstants.DirectKeyUseAlg, SecurityAlgorithms.Aes256CbcHmacSha512);
// Create the JWT and write it to a string
var jwtSecurityToken = new JwtSecurityTokenHandler().CreateJwtSecurityToken(
issuer: _configuration.GetSection("TokenAuthentication:Issuer").Value,
audience: _configuration.GetSection("TokenAuthentication:Audience").Value,
subject: new ClaimsIdentity(claims),
notBefore: now,
expires: now.Add(TimeSpan.FromMinutes(5)),
now,
signingCredentials: new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256),
encryptingCredentials: encryptingCredentials
);
var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwtSecurityToken);
In a dotnet core service and I want to be able to decrypt the token in JavaScript. I've tried the solution from 'Decrypting signature and Veryifying JWT' but can't get further than 'Error: Malformed UTF-8 data'.
Is there a simple solution?