Skip to content

Commit

Permalink
Encode EPK as a JSON object and not an escaped string
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Domzalski authored and jamiehankins committed Jul 17, 2024
1 parent 88e2d87 commit 9219d4e
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.IdentityModel.Abstractions;
using Microsoft.IdentityModel.Logging;
using Microsoft.IdentityModel.Tokens;
using Microsoft.IdentityModel.Tokens.Json;
using JsonPrimitives = Microsoft.IdentityModel.Tokens.Json.JsonSerializerPrimitives;
using TokenLogMessages = Microsoft.IdentityModel.Tokens.LogMessages;

Expand Down Expand Up @@ -1070,7 +1071,15 @@ internal static byte[] WriteJweHeader(
writer.WriteString(JwtHeaderUtf8Bytes.Kid, encryptingCredentials.KeyExchangePublicKey.KeyId);

if (SupportedAlgorithms.EcdsaWrapAlgorithms.Contains(encryptingCredentials.Alg))
writer.WriteString(JwtHeaderUtf8Bytes.Epk, JsonWebKeyConverter.ConvertFromSecurityKey(encryptingCredentials.Key).RepresentAsAsymmetricPublicJwk());
{
writer.WritePropertyName(JwtHeaderUtf8Bytes.Epk);
string publicJwk = JsonWebKeyConverter.ConvertFromSecurityKey(encryptingCredentials.Key).RepresentAsAsymmetricPublicJwk();
#if NET6_0_OR_GREATER
writer.WriteRawValue(publicJwk);
#else
JsonPrimitives.WriteAsJsonElement(ref writer, publicJwk);
#endif
}
}
else
{
Expand Down

0 comments on commit 9219d4e

Please sign in to comment.