---
title: "Encryption functions"
description: "CoraDB hash functions MD5, SHA1 and SHA2 with verified examples, and how to compute checksums of strings and values."
url: "https://www.coradb.ai/manual/sql/function/encryption_fn.html"
markdown_url: "https://www.coradb.ai/manual/markdown/sql/function/encryption_fn.md"
product: "CoraDB"
version: "1.0"
keywords: "md5, sha1, sha2, sha-256, hash function, checksum, encryption functions, coradb"
---

# Encryption functions

## MD5

```sql
MD5(string)
```

The **MD5** function returns the MD5 128-bit checksum for the input character string. The result value is displayed as a character string that is expressed in 32 hexadecimals, which you can use to create hash keys, for example.

**Parameters**

- `string`: Input string. If a value that is not a **VARCHAR** type is entered, it will be converted to **VARCHAR**.

**Return type:** STRING

The return value is a **VARCHAR** (32) type and if an input parameter is **NULL**, **NULL** will be returned.

```sql
SELECT MD5('coradb');
```

| MD5('coradb') |
|---|
| 5552398cf1d9a272c19f35befdd6665b |

```sql
SELECT MD5(255);
```

| MD5(255) |
|---|
| fe131d7f5a6b38b23cc967316c13dae2 |

```sql
SELECT MD5('01/01/2010');
```

| MD5('01/01/2010') |
|---|
| 4a2f373c30426a1b8e9cf002ef0d4a58 |

```sql
SELECT MD5(CAST('2010-01-01' as DATE));
```

| MD5(CAST('2010-01-01' as DATE)) |
|---|
| 4a2f373c30426a1b8e9cf002ef0d4a58 |

## SHA1

```sql
SHA1(string)
```

The **SHA1** function calculates an SHA-1 160-bit checksum for the string, as described in RFC 3174 (Secure Hash Algorithm).

**Parameters**

- `string`: target string to be encrypted

**Return type:** STRING

The value is returned as a string of 40 hex digits, or NULL if the argument is NULL.

```sql
SELECT SHA1('coradb');
```

| SHA1('coradb') |
|---|
| FA4D432B09FA3736504EE74F25748631B0893AC3 |

## SHA2

```sql
SHA2(string, hash_length)
```

The **SHA2** function calculates the SHA-2 family of hash functions (SHA-224, SHA-256, SHA-384, and SHA-512). The first argument is the cleartext string to be hashed. The second argument indicates the desired bit length of the result, which must have a value of 224, 256, 384, 512, or 0 (which is equivalent to 256).

**Parameters**

- `string`: target string to be encrypted

**Return type:** STRING

If either argument is NULL or the hash length is not one of the permitted values, the return value is NULL. Otherwise, the function result is a hash value containing the desired number of bits.

```sql
SELECT SHA2('coradb', 256);
```

| SHA2('coradb', 256) |
|---|
| 6F4FB46C02F8E726E8EFAE0A4DF9B64DE4BDED9FFD9AD7359D3E6D026B4A0FC6 |

```sql
SELECT SHA2('coradb', 224);
```

| SHA2('coradb', 224) |
|---|
| 83E173EAF94A7BFD1324456447C8D5675E41DA843AFBA991D978C955 |
