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

Failure to sign JWT using RSA key #49

Open
dawid86 opened this issue Dec 18, 2023 · 1 comment
Open

Failure to sign JWT using RSA key #49

dawid86 opened this issue Dec 18, 2023 · 1 comment

Comments

@dawid86
Copy link

dawid86 commented Dec 18, 2023

Hi!

I faced an issue using your library to sign JWT with an RSA key.

I use Dart to create code for handling Firebase Functions, so here's my pubspec.yaml:

name: functions
version: 1.0.0
environment:
  sdk: '>=2.9.0 <3.0.0'
dependencies:
  firebase_functions_interop: ^1.0.2
  dart_jsonwebtoken:
  jaguar_jwt:
  uuid:
dev_dependencies:
  build_runner: ^1.9.0
  build_node_compilers: 

I'm using Dart 2.9.3, because node compilers do not support Dart v3.

I'm testing it using your samples:

void rs256() {
  String token;

  /* Sign */ {
    // Create a json web token
    final jwt = JWT(
      {
        'id': 123,
        'server': {
          'id': '3e4fc296',
          'loc': 'euw-2',
        }
      },
      issuer: 'https://github.com/jonasroussel/dart_jsonwebtoken',
    );

    // Sign it
    final pem = '''
-----BEGIN RSA PRIVATE KEY-----
MIIJKQIBAAKCAgEAjR/olnPfRAJx4LNYmIEU0StWjzvkC6wX6XdYLuSyI8aBsoVl
GjltsyjwpjZGJdYCHLc1px36r2pwPF8At9ldJ665CrYfid9Y0hV1icIlnNb8cNHW
OKJmKNarMbAVNP+HVdTSGx6qJ1o5NgJqZVf5Nku/4AUhCjKazt7sOF5im3uHigxl
y9Wgz+s5ztvo6Lx9b/gtce+W+oxzsWSpFg4gMoN7PiRYSZ6vId+PA6RfrbT4Ae5f
yI7xIoaxYmIc7xby5AGySJUvXK7gn8ToK3WyWMQFB4F25f+9BPaTWhWUjIk3vdd7
Hi8yqnNZbR2B+wVbIzLouCn9C25Ia+R5LzMo3B3SAWbl4heVKELJdu+0C++tH0Dj
eIN2OMUfxUeKNU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8NJxY/nZYBWiWMgE85h6gdyARvSHXa+9kW6vSZcf0FAzu8tDPTOlXW+rs5
6V3rE409VK7Zgs+ft8mhOVzu3j08angw9aSsKG64WBbyyDA/jR4cU79yk9lcIs9N
JNwMYjJKn9vp21Fpt8vrw2IFNcy4IX9gIMaJQ6tA0ZXH7BG4081vJ3LAnj0egreV
aCMe2urjXWetMACV2Tmi9fmqmoOjyb/75+EDzwU9zBeuEH5qUVbve+s8VJFq93Mh
8AP8EMlP9A9swIUwvlKLN7bF/UKHboihAoIBAQCQi8myiKXHHEBmCLGhFcGZyHoP
XtGk0dVMH8qTi2thRAUg1QalBECQw/0bgKDMMPjkUSPCje5l3Ji6WN1XV2xnaG13
6xpnp316Pxw09i3U0emgfr9NK1G1YkQebBZ67j+oPA+oEN1ly3g6KiRMYzT+Ovww
6qYuFT3OANAg2BLd+DiKPBfC9CiGr4ZKYOWISsQoY0fbApqHh5NPiwusqUsPfBAs
Hu24jDI+6SUVnDLT8nQHseSxuqEA/5QG0RbHH2+Prb1Lyg41KSc5SimGyS1ec7Bk
8xUwUa2g6UTJwKeQlHIuZaCVKDLeBf0uhQxqG17y76RpqbNCoFOagVicxShU
-----END RSA PRIVATE KEY-----
''';
    final key = RSAPrivateKey(pem);

    token = jwt.sign(key, algorithm: JWTAlgorithm.RS256);

    print('Signed token: $token\n');
  }
}

But failing with error:

Error: Value of "this" must be of type nullish or must be the global object

An interesting fact is that HMAC key (SecretKey) works.

I'd appreciate your support.

(PS - this is test Private Key, so I have no issue with sharing it here ;) )

@jonasroussel
Copy link
Owner

Hey @dawid86,

I installed an old version of Dart to try to run this code but I faced multiple problems during pub get without ever finding a solution to install the packages. Unfortunately, on closer examination, I think the problem come from the pointycastle library (the one used for RSA/ECDSA) and I don't think I can solve your problem...

I'll leave that issue open, maybe someone will have a solution. I will also continue my research on this problem.

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

2 participants