我想将我的 JSON 对象加密为 JWE 令牌。我正在使用带有 C# 语言的 JOSE NuGet SDK。我使用 A256KW JweAlgorithm 作为密钥,使用 A256GCM 作为 JweEncryption。谁能帮我找出我做错了什么?
string key = "Some Key";
// Create Security key using private key above:
// not that latest version of JWT using Microsoft namespace instead of System
var securityKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.UTF8.GetBytes(key));
//Some PayLoad that contain information about the customer
var payload = new JwtPayload
{
{ "page ", "2 "},
{ "sc", "http://dummy.com/"},
};
var payload1 = Newtonsoft.Json.JsonConvert.SerializeObject(anyPayJson);
string token_1 = JWE.Encrypt(payload1, new[] { new JweRecipient(JweAlgorithm.A256KW, key, null) }, JweEncryption.A256GCM);
我是 JOSE JWT 的新手,不知道如何使用 JWE 算法来包装密钥。我在处理它时遇到错误:
AesKeyWrap 管理算法期望密钥为 byte[] 数组。