function md5()

Using MD5 function in MariaDB

Using the MD5 algorithm in MariaDB is very easy because it has a native MD5() function.

The return value is a 32-hex digit string, and as of MariaDB 5.5, is a nonbinary string in the connection character set and collation, determined by the values of the character_set_connection and collation_connection system variables. Before 5.5, the return value was a binary string.

NULL is returned if the argument was NULL.

Syntax:

MD5(string)

Basic example:

SELECT MD5('Hello world!');

The above example will output:

86fb269d190d2c85f6e0468ceca42a20

Example #2 with salt before string to be encrypted:

In some cases, it is worth using a salted MD5 hash for added security. This means that you add the "salt string" before or after the string to be encrypted.

            SELECT MD5(CONCAT('yourSalt', 'Hello world!'));
        

Example #2 will output:

a17602be9d6201a338243d8d7693f5bf

Note: Be aware that using encryption functions in a database usually means that the original, unencrypted text will be stored in the database log, which in some cases can be a potential security risk.

External resources about MD5 in MariaDDB:

MariaDB.com