Link to this headingCWT
Binary version of JWT
Link to this headingExample
#!/usr/bin/env python3
"""
Example demonstrating CBOR Web Token (CWT) vs JSON Web Token (JWT)
"""
"""Create and display a JWT token"""
=
=
=
=
=
return ,
"""Create and display a CWT token"""
=
=
=
=
=
return ,
"""Compare the sizes of JWT and CWT"""
=
=
= * 100
, =
, =
"""
CBOR Web Token (CWT) vs JSON Web Token (JWT)
============================================================
JWT (JSON Web Token) Example
============================================================
Claims:
{
"iss": "auth.example.com",
"sub": "user123",
"aud": "api.example.com",
"exp": 1766603839,
"iat": 1766517439
}
Encoded JWT (215 bytes):
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoLmV4YW1wbGUuY29tIiwic3ViIjoidXNlcjEyMyIsImF1ZCI6ImFwaS5leGFtcGxlLmNvbSIsImV4cCI6MTc2NjYwMzgzOSwiaWF0IjoxNzY2NTE3NDM5fQ.Q6xpLbFcgnXRxPBn7ua66AhzeKNgJ6Ks8SnZm1x2iMU
Structure: Header (36b) . Payload (134b) . Signature (43b)
============================================================
CWT (CBOR Web Token) Example
============================================================
Claims (integer keys):
1 (iss): auth.example.com
2 (sub): user123
3 (aud): api.example.com
4 (exp): 1766603839
6 (iat): 1766517439
CBOR-encoded: 57 bytes
Hex: a50170617574682e6578616d706c652e636f6d026775736572313233036f6170692e6578616d706c652e636f6d041a694c3c3f061a694aeabf
Full CWT with COSE structure: 78 bytes
"""