Skip to content

Encryption functions

View as Markdown
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.

SELECT MD5('coradb');
MD5('coradb')
5552398cf1d9a272c19f35befdd6665b
SELECT MD5(255);
MD5(255)
fe131d7f5a6b38b23cc967316c13dae2
SELECT MD5('01/01/2010');
MD5('01/01/2010')
4a2f373c30426a1b8e9cf002ef0d4a58
SELECT MD5(CAST('2010-01-01' as DATE));
MD5(CAST('2010-01-01' as DATE))
4a2f373c30426a1b8e9cf002ef0d4a58
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.

SELECT SHA1('coradb');
SHA1('coradb')
FA4D432B09FA3736504EE74F25748631B0893AC3
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.

SELECT SHA2('coradb', 256);
SHA2('coradb', 256)
6F4FB46C02F8E726E8EFAE0A4DF9B64DE4BDED9FFD9AD7359D3E6D026B4A0FC6
SELECT SHA2('coradb', 224);
SHA2('coradb', 224)
83E173EAF94A7BFD1324456447C8D5675E41DA843AFBA991D978C955