Returns the specified value in hashed form.
HASH( string-expression[, algorithm ] )
string-expression The value to be hashed. This parameter is case sensitive, even in case-insensitive databases.
algorithm The algorithm to use for the hash. Possible values include: CRC32, MD5, SHA1, SHA1_FIPS, SHA256, SHA256_FIPS. By default, the MD5 algorithm is used. ECC encryption and FIPS-certified encryption require a separate license. See SQL Anywhere security option.
Following are the return types, depending on the algorithm used:
CRC32 returns a hexadecimal string. Use the HEXTOINT function to convert the hexadecimal string to a 32-bit integer. See HEXTOINT function [Data type conversion].
MD5 returns a VARCHAR(32)
SHA1 returns a VARCHAR(40)
SHA1_FIPS returns a VARCHAR(40)
SHA256 returns a VARCHAR(40)
SHA256_FIPS returns a VARCHAR(40)
Using a hash converts the value to a byte sequence that is unique to each value passed to the function.
If the database server was started with the -fips option, the algorithm used, or the behavior, may be different, as follows:
SHA1_FIPS is used if SHA1 is specified
SHA256_FIPS is used if SHA256 is specified
an error is returned if MD5 is specified
the CRC32 algorithm is allowed in FIPS mode because it is not considered a cryptographic algorithm
All the algorithms are one-way hashes. It is not possible to re-create the original string from the hash.
SQL/2008 Vendor extension.
The following example creates a table called user_info to store information about the users of an application, including their user ID and password. One row is also inserted into the table. The password is hashed using the HASH function and the SHA256 algorithm. Storing hashed passwords in this way can be useful if you do not want to store passwords in clear text, yet you have an external application that needs to compare passwords.
CREATE TABLE user_info ( employee_id INTEGER NOT NULL PRIMARY KEY, user_name CHAR(80), user_pwd CHAR(80) ); INSERT INTO user_info VALUES ( '1', 's_phillips', HASH( 'mypass', 'SHA256' ) ); |
![]() |
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |