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

This JsonWebKey does not support the 'sign' operation. #60

Open
digitalrbnz opened this issue Nov 10, 2024 · 0 comments
Open

This JsonWebKey does not support the 'sign' operation. #60

digitalrbnz opened this issue Nov 10, 2024 · 0 comments

Comments

@digitalrbnz
Copy link

digitalrbnz commented Nov 10, 2024

I am attempting to sign using RSA/PS512 and am getting this error when running the build() function.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: This JsonWebKey does not support the 'sign' operation.
#0 JsonWebKey._assertCanDo (package:jose/src/jwk.dart:410:7)
jwk.dart:410
#1 JsonWebKey.sign (package:jose/src/jwk.dart:271:5)
jwk.dart:271
#2 new _JwsRecipient._sign (package:jose/src/jws.dart:159:16)
jws.dart:159
#3 JsonWebSignatureBuilder.build. (package:jose/src/jws.dart:193:28)
jws.dart:193
#4 MappedListIterable.elementAt (dart:_internal/iterable.dart:425:31)
iterable.dart:425
#5 ListIterator.moveNext (dart:_internal/iterable.dart:354:26)
iterable.dart:354
#6 new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
growable_array.dart:189
#7 new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
growable_array.dart:150
#8 new List.of (dart:core-patch/array_patch.dart:39:18)
array_patch.dart:39
#9 ListIterable.toList (dart:_internal/iterable.dart:224:7)
iterable.dart:224
#10 JsonWebSignatureBuilder.build (package:jose/src/jws.dart:195:8)

Example code below

   // create a builder, decoding the JWT in a JWS, so using a
    // JsonWebSignatureBuilder
    var builder = new Jose.JsonWebSignatureBuilder();

    // set the content
    builder.jsonContent = claims.toJson();

    // add a key to sign, can only add one for JWT
    builder.addRecipient(
        new Jose.JsonWebKey.fromJson(
            {"kty": "RSA", 'k":privateKey}),
        algorithm: "PS512");

    // build the jws
    var jws = builder.build();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant