How can one best compress a JWT before making a QR code from it?

I'm working on an app that will eventually display a QR code on a phone, that can then be scanned by the same app on someone else's phone.

The information in the QR code is a JWT. In fact, it's a signed JWT inside another signed JWT. The inner JWT is signed by my backend, with an expiration date of 12 weeks. And the outer JWT is signed by the app on the phone, with an expiration date of 1 minute.

The goal of that is to make sure that if anybody is hoping to steal someone else's QR code, that even if they manage to get a screenshot or photo or whatever, that that code wouldn't be useful anymore after a minute.

Anyhow, one downside is that right now the generated QR code is huge.

I've been struggling with how to compress the data to make a smaller QR code. I've tried installing a zipping package, using that to compress the JWT and then trying to generate a QR code from that binary. But so far I'm always only saving just a few bytes, if any. I assume there must be a better way.

Does anybody know a way that is effective? Preferably using only javascript functions and packages that work in the browser.

1

1 Answer

You could start by decoding the Base64, which will reduce the size by 25%. Then you could try a short-string compressor on the resulting JSON. Maybe try shoco with a custom model for JSON.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like