Available in CSML v1.5+
Loading...
Loading...
Loading...
You can easily encode and decode data to and from Base64 and Hex:
This can for example be useful when using Basic Auth in HTTP calls:
But in general, they are useful methods to encode/decode non-URL-safe or non-ASCII data to ensure exchanges between systems run smoothly.
Base64 and Hex are NOT encryption methods!
The JWT module lets you encode, decode and verify Json Web Tokens easily!
exemple: JWT(data).sign(algorithm, secret)
data
: json object to sign and convert to a JWT token
algorithm
: see below
secret
: a secret string used to sign the JWT
This method returns a properly encoded JWT as a string.
exemple: JWT(token).decode(algorithm, secret)
token
: the token to decode
Note: decode
does not try to verify that the token is valid. It simply decodes its payload back to the original form.
This method returns the full JWT data, in the form:{ "payload": { ... your data }, "headers": { "alg": ALG, "typ": "JWT" }}
exemple: JWT(token).verify(claims, algorithm, secret)
claims
: set of claims (in JSON form) to verify the JWT against
Note: only valid claims are verified. See the list of official claims in the JWT specs here.
This method returns the full JWT data, in the form:{ "payload": { ... your data }, "headers": { "alg": ALG, "typ": "JWT" }}
JWT supports the following algorithms: HS256
, HS384
, HS512
(corresponding to HMAC using SHA-256, SHA-384 and SHA-512 respectively).
The secret key must be a valid, url-safe string.
When a sign, decode or verify operation fails, Null
is returned and a say Error(error_message)
is emitted.
Encode data using hash and HMAC methods:
The data
parameter is the data to encrypt or encode, and it must be a string.
The algorithm must be one of the following values:
Unlike the create_hash
method, create_hmac
requires a key to function. The list of accepted algorithms is the same.
The encoding must be either "base64"
or "hex"
.
When any operation fails, Null
is returned and a say Error(error_message)
is emitted.