# Crypto Module

Simple, fast crypto service. Import

```
import crypto from 'crypto';
```

### Methods

[md5(string)](https://docs.medable.com/reference#section-md5-string-)\
[md5Hmac(string, string)](https://docs.medable.com/reference#section-md5hmac-string-string-)\
[sha1(string)](https://docs.medable.com/reference#section-sha1-string-)\
[sha1Hmac(string, string)](https://docs.medable.com/reference#section-sha1hmac-string-string-)\
[sha256(string)](https://docs.medable.com/reference#section-sha256-string-)\
[sha256Hmac(string, string)](https://docs.medable.com/reference#section-sha256hmac-string-string-)\
[sha512(string)](https://docs.medable.com/reference#section-sha512-string-)\
[sha512Hmac(string, string)](https://docs.medable.com/reference#section-sha512hmac-string-string-)\
[rsa.encrypt(apiKey, payload, outputEncoding=buffer, inputEncoding=utf8)](https://docs.medable.com/reference#section-rsa-encrypt-apikey-payload-outputencoding-buffer-inputencoding-utf8-)\
[rsa.decrypt(apiKey, payload, outputEncoding=utf8)](https://docs.medable.com/reference#section-rsa-decrypt-apikey-payload-outputencoding-utf8-)

### md5(string)

**Arguments**

* `value` (String) string to hash

**Returns**

* `value` (String) hash value

### md5Hmac(string, string)

**Arguments**

* `secret` (String) secret key
* `value` (String) string to hash

**Returns**

* `value` (String) hash value

### sha1(string)

**Arguments**

* `value` (String) string to hash

**Returns**

* `value` (String) hash value

### sha1Hmac(string, string)

**Arguments**

* `secret` (String) secret key
* `value` (String) string to hash

**Returns**

* `value` (String) hash value

### sha256(string)

**Arguments**

* `value` (String) string to hash

**Returns**

* `value` (String) hash value

### sha256Hmac(string, string)

**Arguments**

* `secret` (String) secret key
* `value` (String) string to hash

**Returns**

* `value` (String) hash value

### sha512(string)

**Arguments**

* `value` (String) string to hash

**Returns**

* `value` (String) hash value

### sha512Hmac(string, string)

**Arguments**

* `secret` (String) secret key
* `value` (String) string to hash

**Returns**

* `value` (String) hash value

### rsa.encrypt(apiKey, payload, outputEncoding=buffer, inputEncoding=utf8)

Encrypt a JSON object or a string using an app's RSA public key

**Arguments**

* `apiKey` (String) The app api key that holds the key pair
* `payload` (String|Object) string or JSON object to encrypt
* `outputEncoding` (String=buffer) Support output encodings are hex, base64, buffer and binary
* `inputEncoding` (String=utf8) Supported input encodings are hex, base64 and utf8

**Returns**

* `value` (Buffer|String) encrypted value

### rsa.decrypt(apiKey, payload, outputEncoding=utf8)

Decrypt a buffer or base64 encoded string app's RSA private key

**Arguments**

* `apiKey` (String) The app api key that holds the key pair
* `payload` (String|Buffer) string or buffer to decrypt
* `outputEncoding` (String=utf8) Support output encodings are hex, base64, buffer, binary, utf8 and json. If `json` is specified, decrypt will parse the resulting string..

**Returns**

* `value` (String|Object) decrypted value

### Examples

Crypto Example

```
import crypto, { rsa } from 'crypto'

const apiKey = 'Lndee3dK9ZbMphlqQDtW9b', 
      encrypted = rsa.encrypt(
        apiKey, 
        'Seymour R. Goff',
        'base64'
      )

return {
  sha256: crypto.sha256("Seymour R. Goff"),
  sha256Hmac: crypto.sha256Hmac("loose lips might sink ships", "Seymour R. Goff"),
  encrypted: encrypted,
  decrypted: rsa.decrypt(apiKey, encrypted)
}
```

Crypto Example Response

```
{
    "object": "result",
    "data": {
        "decrypted": "Seymour R. Goff",
        "encrypted": "c8ZT8Cv4dH...xuR3BuTQ==",
        "sha256": "bdd3e9c4cf...19200b8120",
        "sha256Hmac": "4576a34032...7e7a52e139"
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.medable.com/cortex-api/scripting/modules-1/crypto-module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
