Skip to content

Crypto

AES encryption/decryption, HMAC, JWT tokens, and secure random generation.

7 modules

ModuleDescription
DecryptDecrypt data using AES encryption
EncryptEncrypt data using AES encryption
HMACGenerate HMAC signature
Create JWTCreate a signed JWT token
Verify JWTVerify and decode a JWT token
Random BytesGenerate cryptographically secure random bytes
Random StringGenerate cryptographically secure random string

Modules

Decrypt

crypto.decrypt

Decrypt data using AES encryption

Parameters:

NameTypeRequiredDefaultDescription
ciphertextstringYes-Encrypted data to decrypt
keystringYes-Encryption key
modeselect (CBC, GCM)NoGCMAES cipher mode (CBC, GCM, etc.)
input_formatselect (base64, hex)Nobase64Format of the input ciphertext (hex or base64)

Output:

FieldTypeDescription
plaintextstringDecrypted plaintext
algorithmstringAlgorithm used for decryption

Example: Decrypt AES-GCM ciphertext

yaml
ciphertext: <base64-encoded-ciphertext>
key: my-secret-passphrase
mode: GCM

Encrypt

crypto.encrypt

Encrypt data using AES encryption

Parameters:

NameTypeRequiredDefaultDescription
plaintextstringYes-Data to encrypt
keystringYes-Encryption key
modeselect (CBC, GCM)NoGCMAES cipher mode (CBC, GCM, etc.)
output_formatselect (base64, hex)Nobase64Format for the output ciphertext (hex or base64)

Output:

FieldTypeDescription
ciphertextstringEncrypted ciphertext
algorithmstringAlgorithm used for encryption
modestringCipher mode used

Example: Encrypt with AES-GCM

yaml
plaintext: Hello, World!
key: my-secret-passphrase
mode: GCM

HMAC

crypto.hmac

Generate HMAC signature

Parameters:

NameTypeRequiredDefaultDescription
messagestringYes-Message to sign
keystringYes-Message to sign
algorithmselect (sha256, sha512, sha1, md5)Nosha256Secret key for HMAC
encodingselect (hex, base64)NohexOutput encoding format

Output:

FieldTypeDescription
signaturestringOutput encoding format
algorithmstringHMAC signature

Create JWT

crypto.jwt_create

Create a signed JWT token

Parameters:

NameTypeRequiredDefaultDescription
payloadobjectYes-JWT payload data (object)
secretstringYes-Secret key for signing the token
algorithmselect (HS256, HS384, HS512, RS256)NoHS256JWT signing algorithm (HS256, RS256, etc.)
expires_innumberNo-Token expiration time in seconds
issuerstringNo-Token issuer claim
audiencestringNo-Intended audience for the token

Output:

FieldTypeDescription
tokenstringGenerated JWT token
algorithmstringAlgorithm used for signing
expires_atstringToken expiration timestamp

Example: Create a JWT with expiration

yaml
payload: {"sub": "user123", "role": "admin"}
secret: my-jwt-secret
algorithm: HS256
expires_in: 3600

Verify JWT

crypto.jwt_verify

Verify and decode a JWT token

Parameters:

NameTypeRequiredDefaultDescription
tokenstringYes-JWT token to verify
secretstringYes-Secret key used to sign the token
algorithmsarrayNo['HS256']Allowed signing algorithms
verify_expbooleanNoTrueWhether to verify the expiration claim
audiencestringNo-Expected audience claim
issuerstringNo-Expected issuer claim

Output:

FieldTypeDescription
validbooleanWhether the token is valid
payloadobjectDecoded JWT payload
headerobjectJWT header data

Example: Verify a JWT token

yaml
token: eyJhbGciOiJIUzI1NiIs...
secret: my-jwt-secret
algorithms: ["HS256"]
verify_exp: true

Random Bytes

crypto.random_bytes

Generate cryptographically secure random bytes

Parameters:

NameTypeRequiredDefaultDescription
lengthnumberYes32Number of bytes
encodingstringNohexOutput encoding

Output:

FieldTypeDescription
bytesstringRandom bytes (encoded)
lengthnumberRandom bytes (encoded)

Random String

crypto.random_string

Generate cryptographically secure random string

Parameters:

NameTypeRequiredDefaultDescription
lengthnumberYes16String length
charsetstringNoalphanumericCharacters to use
uppercasebooleanNoFalseConvert to uppercase

Output:

FieldTypeDescription
stringstringConvert to uppercase
lengthnumberRandom string

Released under the Apache 2.0 License.