MySQL | SHA1( ) Function
The MySQL SHA1() function is used for encrypting a string using the SHA-1 technique. The SHA1 stands for secure hash algorithm and it produces a 160-bit checksum for a user inputted string.
The MySQL SHA1() function returns NULL if the string passed as an argument is a NULL string. The SHA1() function accepts one parameter which is the string to be encrypted.
Syntax:
SHA1(string)
Parameters Used:
string – It is used to specify the plain text string that is to be encrypted.
Return Value:
The SHA1() function in MySQL returns the encrypted string or NULL if the string passed is an empty string.
Supported Versions of MySQL:
- MySQL 5.7
- MySQL 5.6
- MySQL 5.5
- MySQL 5.1
- MySQL 5.0
- MySQL 4.1
Example-1: Implementing SHA1() function on a string.
SELECT
SHA1('geeskforgeeks');
Output:
69c9a5c19c5c27e43cb0efc4c8644ed6d03a110b
Example-2: Implementing SHA1() function on a string which has a combination of characters and integers.
SELECT
SHA1('geeskforgeeks123');
Output:
53ce00666cbef425ab8d06ed652095bea20a1616
Example-3: Implementing SHA1() function on a NULL string and returning the length of the string after compression.
SELECT SHA1(NULL);
Output:
NULL
Recommended Posts:
- MySQL | IF( ) Function
- MySQL | MD5 Function
- MySQL | BIN() Function
- MySQL | USER( ) Function
- MySQL | AES_DECRYPT ( ) Function
- MySQL | CONV( ) Function
- MySQL | COMPRESS( ) Function
- MySQL | Group_CONCAT() Function
- MySQL | DECODE( ) Function
- MySQL | OLD_PASSWORD Function
- MySQL | DES_ENCRYPT ( ) Function
- MySQL | DES_DECRYPT ( ) Function
- MySQL | CONVERT( ) Function
- MySQL | DEFAULT() Function
- MySQL | PASSWORD Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

