.NET Core JWE:没有“cty”标头 - c#

我正在使用以下代码来发布我的JWE:

var signCreds = new SigningCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration["Jwt:SigningKey"])), SecurityAlgorithms.HmacSha256);
var encryptionCreds = new EncryptingCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration["Jwt:Encryptionkey"])), SecurityAlgorithms.Aes128KW, SecurityAlgorithms.Aes128CbcHmacSha256);

var handler = new JwtSecurityTokenHandler();


var jwtSecurityToken = handler.CreateJwtSecurityToken(
  Configuration["Jwt:Issuer"],
  Configuration["Jwt:Audience"],
  new ClaimsIdentity(claims),
  DateTime.UtcNow,
  expiresIn,
  DateTime.UtcNow,
  signCreds,
  encryptionCreds);

但是它没有指定令牌的“ cty”标头-仅包含alg,enc和typ。如果我理解正确,那么必须为加密的JWT设置标头,因此由于缺少标头,我在解析golang中的令牌时遇到问题。

我还尝试了以下发布JWE的方法:

var signCreds = new SigningCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration["Jwt:SigningKey"])), SecurityAlgorithms.HmacSha256);
var encryptionCreds = new EncryptingCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration["Jwt:Encryptionkey"])), SecurityAlgorithms.Aes128KW, SecurityAlgorithms.Aes128CbcHmacSha256);

var handler = new JwtSecurityTokenHandler();

var tokenDescriptor1 = new SecurityTokenDescriptor
  {
     Audience = "you",
     Issuer = "me",
     Subject = new ClaimsIdentity(claims),
     EncryptingCredentials = encryptionCreds
};

var tokenDescriptor2 = new SecurityTokenDescriptor
  {
     Audience = "you",
     Issuer = "me",
     Subject = new ClaimsIdentity(claims),
     EncryptingCredentials = encryptionCreds,
     SigningCredentials = signCreds
};

var tokenDescriptor3 = new SecurityTokenDescriptor
  {
     Audience = "you",
     Issuer = "me",
     Subject = new ClaimsIdentity(claims),
     EncryptingCredentials = encryptionCreds,
     SigningCredentials = signCreds,
     AdditionalHeaderClaims = new Dictionary<string, object> { { "cty", "JWT" } }
   };

var enc = handler.CreateEncodedJwt(tokenDescriptor1);
var encSigned = handler.CreateEncodedJwt(tokenDescriptor2);
var encSignedWithCty = handler.CreateEncodedJwt(tokenDescriptor3);

但是有相同的结果:
.NET Core JWE:没有“cty”标头 - c#

我扫描了library,但没有找到为令牌设置Cty标头的代码。

也许有人知道我错过了什么,或者出了什么问题?

谢谢!

参考方案

好像是图书馆issue

ASP.NET Core Singleton实例与瞬态实例的性能 - c#

在ASP.NET Core依赖注入中,我只是想知道注册Singleton实例是否会比注册Transient实例更好地提高性能?在我看来,对于Singleton实例,创建新对象和相关对象只需花费一次时间。对于Transient实例,此成本将针对每个服务请求重复。因此Singleton似乎更好。但是,在Singleton上使用Transient时,我们可以获得多…

如何在ASP.NET Core Web应用程序中增加JSON反序列化MaxDepth限制 - c#

我们正在将ASP.NET Core 2.1与.NET Framework 4.6.2结合使用。我们有一个客户需要向我们的Web应用程序发送一个很大程度上嵌套的json结构。当他们进行此调用时,我们将输出以下日志并返回错误: 读取器的MaxDepth超过了32。路径“ super.long.path.to property”,第1行,位置42111。”我浏览了…

将Web服务迁移到.NET Core 2.0并返回json - c#

我已经将Web服务迁移到.NET Core 2.0,它可以正常工作,但是在以json字符串获取响应时遇到问题。api上的方法: [HttpGet] [ProducesResponseType(typeof(string), 200)] [ProducesResponseType(typeof(EntityNotFoundErrorResult), 404)]…

.NET Core 2从内存流下载Excel文件 - c#

我当时在.NET Core项目中工作,当时我应该从记录创建电子表格文件并下载它而不将其保存在服务器中。搜索上述标题并没有多大帮助,但给出了一些指示。另外,ASP.NET中使用的大多数方法在.NET Core中均不起作用。因此,我最终可以想出一个效果很好的解决方案。我将在下面的答案中与那些愿意像我一样进行搜索的人分享。 参考方案 首先,您需要安装EPPlus.…

为什么.NET Core API中的POST参数总是为null - c#

我创建了一个简单的.NET核心控制器,并尝试从Angular查询它。问题在于,每当我向登录操作发送发布请求时,我总是会收到空参数!不过,很奇怪的是,在进行调查时,请求正文/有效负载清楚地显示了我的参数已设置。有关我的意思的示例,请参见我的屏幕截图。我已经尽了最大的努力,并且在过去的几个小时中一直在阅读类似的问题,但是没有取得任何成功?所以我的问题是:是什么导…