JSON Web Signature (JWS) is a standard (RFC 7515) for digitally signing arbitrary content using JSON-based data structures. Most JWTs use JWS to provide integrity protection and sender authentication.
JWS uses the familiar three-part JWT structure:
BASE64URL(header).BASE64URL(payload).BASE64URL(signature)
// The signature is computed over:
signature = HMAC-SHA256(
base64url(header) + "." + base64url(payload),
secret
)
// HMAC (symmetric) - same key for sign and verify
// Good for: Single service, internal APIs
signature = HMAC(payload, shared_secret)
// RSA (asymmetric) - private key signs, public verifies
// Good for: Distributed systems, public verification
signature = RSA_Sign(payload, private_key)
verify = RSA_Verify(payload, signature, public_key)