• RANDOM_BYTES( len ) 

This function returns a binary string of len  random bytes generated using the random number generator of the SSL library. Permitted values of len  range from 1 to 1024. For values outside that range, an error occurs. 

RANDOM_BYTES()  can be used to provide the initialization vector for the AES_DECRYPT()  and AES_ENCRYPT()  functions. For use in that context, len  must be at least 16. Larger values are permitted, but bytes in excess of 16 are ignored. 

RANDOM_BYTES()  generates a random value, which makes its result nondeterministic. Consequently, statements that use this function are unsafe for statement-based replication. 

If RANDOM_BYTES()  is invoked from within the mysql  client, binary strings display using hexadecimal notation, depending on the value of the --binary-as-hex . For more information about that option, see Section 4.5.1, “mysql — The MySQL Command-Line Client” . 

• SHA1( str ) , SHA( str ) 

Calculates an SHA-1 160-bit checksum for the string, as described in RFC 3174 (Secure Hash Algorithm). The value is returned as a string of 40 hexadecimal digits, or NULL  if the argument was NULL . One of the possible uses for this function is as a hash key. See the notes at the beginning of this section about storing hash values efficiently. SHA()  is synonymous with SHA1() . 

The return value is a string in the connection character set. 

mysql> SELECT SHA1(’abc’); -> ’a9993e364706816aba3e25717850c26c9cd0d89d’ 

SHA1()  can be considered a cryptographically more secure equivalent of MD5() . However, see the note regarding the MD5 and SHA-1 algorithms at the beginning this section. 

• SHA2( str , hash_length ) 

Calculates the SHA-2 family of hash functions (SHA-224, SHA-256, SHA-384, and SHA-512). The first argument is the plaintext 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). 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. See the notes at the beginning of this section about storing hash values efficiently. 

The return value is a string in the connection character set. 

mysql> SELECT SHA2(’abc’, 224); -> ’23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7’ 

This function works only if MySQL has been configured with SSL support. See Section 6.3, “Using Encrypted Connections” . 

SHA2()  can be considered cryptographically more secure than MD5()  or SHA1() . 

• STATEMENT_DIGEST( statement ) 

Given an SQL statement as a string, returns the statement digest hash value as a string in the connection character set, or NULL  if the argument is NULL . The related STATEMENT_DIGEST_TEXT() 

