---
title: "Crypt"
description: "Static cryptographic functions."
canonical_url: "https://www.zeyos.com/zymba/ref/crypt"
markdown_url: "https://www.zeyos.com/ai/guide/zymba/ref/crypt.md"
section: "zymba-reference"
authority: "reference"
language: "en"
source_repository: "https://cloud.zeyos.com/__doc/zymbaref.json"
source_sha256: "05a361c6ddc32e74f4a6dc16fd06f218210ff1b7ce57f26ca1994bfffc407915"
---

# Crypt

## Crypt

```
object @Crypt() {
	convertPublicKeyRSAToPEM(string $exponent, string $modulus): string {}
	createIV(string $cipher): string {}
	createJWT(object $claims, string $key, string $algorithm, object $header): string {}
	createNonce(int $size): string {}
	createNonceRaw(int $size): string {}
	createPassword(int $length): string {}
	createTimeOrderedUUID(): string {}
	createUUID(): string {}
	decrypt(string $string, string $key, string $cipher, string $iv): string {}
	encrypt(string $string, string $key, string $cipher, string $iv): string {}
	equalsTimeConstant(string $secret, string $input): bool {}
	hash(string $string, string $algorithm, ?string $key): string {}
	hashFile(string $path, string $algorithm, ?string $key): string {}
	hashFileRaw(string $path, string $algorithm, ?string $key): string {}
	hashPassword(string $password): string {}
	hashRaw(string $string, string $algorithm, ?string $key): string {}
	listCiphers(): object {}
	listHashAlgorithms(): object {}
	pbkdf2(string $password, string $salt, string $algorithm, int $iterations, int $length): string {}
	pbkdf2Raw(string $password, string $salt, string $algorithm, int $iterations, int $length): string {}
	verifyJWT(string $jwt, string $key): object {}
	verifyPassword(string $password, string $hash): bool {}
}
```

**Static cryptographic functions.**

## Functions


### `@Crypt.convertPublicKeyRSAToPEM()`


Converts a raw RSA exponent and modulus to a public key in PEM format.

```code
@Crypt.convertPublicKeyRSAToPEM(string $exponent, string $modulus): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| exponent | `string`  |  | "" |
| modulus | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.createIV()`


Creates a suitable initialization vector for a specific cipher from a random source.

```code
@Crypt.createIV(string $cipher): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| cipher | `string`  |  | "aes-192-ecb" |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.createJWT()`


Creates a JSON Web Token (JWT) according to RFC 7519.

```code
@Crypt.createJWT(object $claims, string $key, string $algorithm, object $header): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| claims | `object`  | [name: value] | [] |
| key | `string`  |  | "" |
| algorithm | `string`  |  | "HS256" |
| header | `object`  | [name: value] | [] |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.createNonce()`


Creates a nonce of a specific size in number of bytes from a random source in its hexadecimal string representation.

```code
@Crypt.createNonce(int $size): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| size | `int`  |  | 20 |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.createNonceRaw()`


Creates a nonce of a specific size in number of bytes from a random source as raw binary data.

```code
@Crypt.createNonceRaw(int $size): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| size | `int`  |  | 20 |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.createPassword()`


Creates a secure password of a specific length in number of characters from a random source.

```code
@Crypt.createPassword(int $length): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| length | `int`  |  | 10 |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.createTimeOrderedUUID()`


Creates a version 7 universally unique identifier (UUID) from the current timestamp and a random source according to RFC 4122.

```code
@Crypt.createTimeOrderedUUID(): string
```

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.createUUID()`


Creates a version 4 universally unique identifier (UUID) from a random source according to RFC 4122.

```code
@Crypt.createUUID(): string
```

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.decrypt()`


Decryptes a string with a specific key.

```code
@Crypt.decrypt(string $string, string $key, string $cipher, string $iv): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| string | `string`  |  | "" |
| key | `string`  |  | "" |
| cipher | `string`  |  | "aes-192-ecb" |
| iv | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |
| `null` |  |




### `@Crypt.encrypt()`


Encryptes a string with a specific key.

```code
@Crypt.encrypt(string $string, string $key, string $cipher, string $iv): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| string | `string`  |  | "" |
| key | `string`  |  | "" |
| cipher | `string`  |  | "aes-192-ecb" |
| iv | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.equalsTimeConstant()`


Determines whether two strings are equal based on time-constant string comparison that guards against timing attacks.

```code
@Crypt.equalsTimeConstant(string $secret, string $input): bool
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| secret | `string`  |  | "" |
| input | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `bool` |  |




### `@Crypt.hash()`


Generates the hash of a string in its hexadecimal string representation using a specific algorithm.

```code
@Crypt.hash(string $string, string $algorithm, ?string $key): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| string | `string`  |  | "" |
| algorithm | `string`  |  | "sha1" |
| key | `?string`  |  | non-HMAC |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.hashFile()`


Generates the hash of the content of an existing file in its hexadecimal string representation using a specific algorithm.

```code
@Crypt.hashFile(string $path, string $algorithm, ?string $key): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| path | `string`  |  | "" |
| algorithm | `string`  |  | "sha1" |
| key | `?string`  |  | non-HMAC |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.hashFileRaw()`


Generates the hash of the content of an existing file as raw binary data using a specific algorithm.

```code
@Crypt.hashFileRaw(string $path, string $algorithm, ?string $key): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| path | `string`  |  | "" |
| algorithm | `string`  |  | "sha1" |
| key | `?string`  |  | non-HMAC |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.hashPassword()`


Generates a password hash in the Modular Crypt Format (MCF) using the bcrypt algorithm.

```code
@Crypt.hashPassword(string $password): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| password | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.hashRaw()`


Generates the hash of a string as raw binary data using a specific algorithm.

```code
@Crypt.hashRaw(string $string, string $algorithm, ?string $key): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| string | `string`  |  | "" |
| algorithm | `string`  |  | "sha1" |
| key | `?string`  |  | non-HMAC |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.listCiphers()`


Lists all available ciphers.

```code
@Crypt.listCiphers(): object
```

##### Returns

| Type | Value |
| --- | ---  |
| `object` | [cipher, ...] |




### `@Crypt.listHashAlgorithms()`


Lists all available hash algorithms.

```code
@Crypt.listHashAlgorithms(): object
```

##### Returns

| Type | Value |
| --- | ---  |
| `object` | [algorithm, ...] |




### `@Crypt.pbkdf2()`


Generatesa a PBKDF2 key derived from a password along with a salt in its hexadecimal string representation using a specific algorithm according to RFC 2898.

```code
@Crypt.pbkdf2(string $password, string $salt, string $algorithm, int $iterations, int $length): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| password | `string`  |  | "" |
| salt | `string`  |  | "" |
| algorithm | `string`  |  | "sha1" |
| iterations | `int`  |  | 10000 |
| length | `int`  |  | full key length |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.pbkdf2Raw()`


Generates a PBKDF2 key derived from a password along with a salt as raw binary data using a specific algorithm according to RFC 2898.

```code
@Crypt.pbkdf2Raw(string $password, string $salt, string $algorithm, int $iterations, int $length): string
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| password | `string`  |  | "" |
| salt | `string`  |  | "" |
| algorithm | `string`  |  | "sha1" |
| iterations | `int`  |  | 10000 |
| length | `int`  |  | full key length |

##### Returns

| Type | Value |
| --- | ---  |
| `string` |  |




### `@Crypt.verifyJWT()`


Verify a JSON Web Token (JWT) against a specific key according to RFC 7519 and returns its header parameters and claims.

```code
@Crypt.verifyJWT(string $jwt, string $key): object
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| jwt | `string`  |  | "" |
| key | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `object` | ["header": [name: value, ...], "claims": [name: value, ...]] |
| `null` |  |




### `@Crypt.verifyPassword()`


Verify a password against a specific password hash in the Modular Crypt Format (MCF).

```code
@Crypt.verifyPassword(string $password, string $hash): bool
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| password | `string`  |  | "" |
| hash | `string`  |  | "" |

##### Returns

| Type | Value |
| --- | ---  |
| `bool` |  |
