Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.NotSupportedException: 'Key wrap is not supported for algorithm: 'A256GCM' with a key of type 'EC' and size of 521 bits.' #587

Open
zahradardan opened this issue Jul 21, 2024 · 1 comment
Labels
question Further information is requested

Comments

@zahradardan
Copy link

zahradardan commented Jul 21, 2024

i have error in writer3.WriteTokenString(asyDescriptorPlainText); with exception

System.NotSupportedException: 'Key wrap is not supported for algorithm: 'A256GCM' with a key of type 'EC' and size of 521 bits.'

        string publicKeyStringShahkar = "-******************-";
         

        TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);

        int secondsSinceEpoch = (int)t.TotalSeconds;
          
        var asymmetricJwkKey = AsymmetricJwk.FromPem(publicKeyStringShahkar);

        var payload = new
        {
            data = input,
            iat = secondsSinceEpoch
        };

        string jsonPayload = JsonConvert.SerializeObject(payload);

        var asyDescriptorPlainText = new PlaintextJweDescriptor(asymmetricJwkKey,
            KeyManagementAlgorithm.EcdhEsA256KW, EncryptionAlgorithm.A256Gcm)
        {
            Payload = jsonPayload
        };


        // The descriptor sets the 'alg' with value 'A256GCMKW' and 'enc' with value 'A128CBC-HS256'
        var writer3 = new JwtWriter();
        var token3 = writer3.WriteTokenString(asyDescriptorPlainText);
@ycrumeyrolle
Copy link
Collaborator

Can you please precise:

  • dotnet version target
  • operating system
  • JWT package version

Also if you have to get the current time in Epoch time format:

long secondsSinceEpoch = EpochTime.UtcNow;

It is important to use int64 instead of int32 for avoiding the Year 2038 problem.

@ycrumeyrolle ycrumeyrolle added the question Further information is requested label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants