Encoding Functions¶
Encoding and decoding functions: Base64, hex, URL encoding, and more.
Summary¶
| Function | Signature | Description |
|---|---|---|
base64_decode |
string -> string |
Decode base64 string |
base64_encode |
string -> string |
Encode string to base64 |
base64url_decode |
string -> string |
Decode base64url (RFC 4648 §5) string |
base64url_encode |
string -> string |
Encode string to base64url (RFC 4648 §5, no padding) |
hex_decode |
string -> string |
Decode hex string |
hex_encode |
string -> string |
Encode string to hex |
html_escape |
string -> string |
Escape HTML special characters |
html_unescape |
string -> string |
Unescape HTML entities |
jwt_decode |
string -> object |
Decode JWT payload (claims) without verification |
jwt_header |
string -> object |
Decode JWT header without verification |
Functions¶
base64_decode¶
Decode base64 string
Signature: string -> string
Examples:
# Decode hello
base64_decode('aGVsbG8=') -> \"hello\"
# Decode test
base64_decode('dGVzdA==') -> \"test\"
# Empty string
base64_decode('') -> \"\"
CLI Usage:
base64_encode¶
Encode string to base64
Signature: string -> string
Examples:
# Encode hello
base64_encode('hello') -> \"aGVsbG8=\"
# Encode test
base64_encode('test') -> \"dGVzdA==\"
# Empty string
base64_encode('') -> \"\"
CLI Usage:
base64url_decode¶
Decode base64url (RFC 4648 §5) string
Signature: string -> string
Examples:
# Decode hello
base64url_decode('aGVsbG8') -> "hello"
# Decode test
base64url_decode('dGVzdA') -> "test"
# Empty string
base64url_decode('') -> ""
CLI Usage:
base64url_encode¶
Encode string to base64url (RFC 4648 §5, no padding)
Signature: string -> string
Examples:
# Encode hello
base64url_encode('hello') -> "aGVsbG8"
# Encode test
base64url_encode('test') -> "dGVzdA"
# Empty string
base64url_encode('') -> ""
CLI Usage:
hex_decode¶
Decode hex string
Signature: string -> string
Examples:
# Decode hello
hex_decode('68656c6c6f') -> \"hello\"
# Decode test
hex_decode('74657374') -> \"test\"
# Empty string
hex_decode('') -> \"\"
CLI Usage:
hex_encode¶
Encode string to hex
Signature: string -> string
Examples:
# Encode hello
hex_encode('hello') -> \"68656c6c6f\"
# Encode test
hex_encode('test') -> \"74657374\"
# Empty string
hex_encode('') -> \"\"
CLI Usage:
html_escape¶
Escape HTML special characters
Signature: string -> string
Examples:
# Escape tags
html_escape('<div>') -> \"<div>\"
# Escape ampersand
html_escape('a & b') -> \"a & b\"
# Escape quotes
html_escape('\"quoted\"') -> \""quoted"\"
# Sanitize input
html_escape(user_input) -> safe for HTML
CLI Usage:
html_unescape¶
Unescape HTML entities
Signature: string -> string
Examples:
# Unescape tags
html_unescape('<div>') -> \"<div>\"
# Unescape ampersand
html_unescape('a & b') -> \"a & b\"
# Unescape quotes
html_unescape('"quoted"') -> \"\\\"quoted\\\"\"
# Decode entities
html_unescape(escaped) -> original
CLI Usage:
jwt_decode¶
Decode JWT payload (claims) without verification
Signature: string -> object
Examples:
# Extract subject claim
jwt_decode('eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyXzEyMyJ9.sig').sub -> \"user_123\"
# Extract name claim
jwt_decode('eyJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiSm9obiJ9.sig').name -> 'John'
CLI Usage:
jwt_header¶
Decode JWT header without verification
Signature: string -> object
Examples:
# Extract algorithm
jwt_header('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.payload.sig').alg -> \"HS256\"
# Extract type
jwt_header('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.payload.sig').typ -> \"JWT\"
CLI Usage: