# SHA256

**The SHA256 function takes a single String as input and returns the hash of the input as a Hex- or Base64-encoded string, arrived at via the SHA-256 hashing algorithm.**

This function requires a single [String](../../variable-data-types/the-text-variable-data-type) as input. As an option, it also accepts another string that define if Hex or Base64 encoding will to be used to calculate the output: a string that gives the hash of the first input, as calculated by the [SHA-256 hashing algorithm.](https://en.wikipedia.org/wiki/SHA-2)

#### Declaration

```javascript
SHA256(string, encode) -> hash
```

#### Parameters

**string** (required, type:_string_) Any string.

**encode** (optional, type:_string_, default: "Hex")

The string "Hex" or "Base64". This defines if the hash of **string** will be Hex- or Base64-encoded, respectively.

If no value is given for **encode**, SHA256 will return the Hex-encoded hash. If a value other than "Hex" or "Base64" is given for **encode**, SHA256 will throw an error.

#### Return Values

**hash**(type: _string_) The hash of the input as calculated by the [SHA-256 hashing algorithm.](https://en.wikipedia.org/wiki/SHA-2)

#### Examples

The following example returns the Hex-encoded hash of the string "This is a string." as calculated by the SHA-256 hashing algorithm:

```javascript
SHA256("This is a string.") => "a13da8b26228f4c73e6c7447619b4b69a83dc9e94cca8044f3afbf4489da8d5c"
```

The following example also returns the Hex-encoded hash of the string "This is a string." as calculated by the SHA-256 hashing algorithm. Note that it returns the same output as the above example; there is no difference in output between explicitly defining "Hex" as the value for **encode** and not defining **encode** at all:

```javascript
SHA256("This is a string.", "Hex") => "a13da8b26228f4c73e6c7447619b4b69a83dc9e94cca8044f3afbf4489da8d5c"
```

The following example returns the Base64-encoded hash of the string "This is a string." as calculated by the SHA-256 hashing algorithm. Note how this differs from the above examples:

```javascript
SHA256("This is a string.", "Base64") => "oT2osmIo9Mc+bHRHYZtLaag9yelMyoBE86+/RInajVw="
```

The following example returns the hash of the email "no-reply@airkit.com" as calculated by the SHA-256 hashing algorithm. Note that within Airscript, an [email](../../variable-data-types/the-email-variable-data-type) is a subcategory of string:

```javascript
SHA256("no-reply@airkit.com") => 7b84e627966985091b9dca5bd9c389cd45f4cb05ab94858654f95710cbca3576
```
