Crypto
The Crypto interface of Azion Runtime: the global crypto object, its subtle property, and the getRandomValues and randomUUID methods.
The Crypto interface gives access to a cryptographically strong random number generator and to cryptographic primitives. In Azion Runtime, the global crypto object is an instance of Crypto, so a function runs these operations without an external library. For more information, refer to Crypto on MDN Web Docs.
Use crypto.randomUUID() to create collision-resistant identifiers for sessions, requests, or traces, and crypto.getRandomValues() to build nonces and tokens. Use crypto.subtle to hash or digest a request payload and verify its integrity before you forward it. The same property validates a signed token, such as a JWT, inside the function, with no call to an origin.
Properties
| Property | Type | Description |
|---|---|---|
crypto.subtle | SubtleCrypto | Gives access to common cryptographic primitives, such as hashing, signing, encryption, and decryption. For more information, refer to SubtleCrypto. |
Methods
| Method | Description |
|---|---|
crypto.getRandomValues(typedArray) | Fills the typed array you pass with cryptographically strong random values and returns it. Accepts up to 65,536 bytes per call. |
crypto.randomUUID() | Returns a randomly generated version 4 UUID, a string of 36 characters. |
A call to crypto.getRandomValues() with more than 65,536 bytes throws. The value a catch block receives is undefined, not an error object: it has no name and no message. Keep each call at or below 65,536 bytes.
Example
This handler generates a UUID with crypto.randomUUID(), then returns it with its length and whether it matches the version 4 format:
The function returns these values. The UUID differs on every call: