DECRYPT function [String]

Decrypts the string using the supplied key and returns a LONG BINARY value.

Syntax
DECRYPT( string-expression, key 
[, algorithm ] 
)
algorithm : 
'AES' 
| 'AES256' 
| 'AES_FIPS' 
| 'AES256_FIPS'
Parameters
  • string-expression   The string to be decrypted. Binary values can also be passed to this function. This parameter is case sensitive, even in case-insensitive databases.

  • key   The encryption key (string) required to decrypt the string-expression. This must be the same encryption key that was used to encrypt the string-expression to obtain the original value that was encrypted. This parameter is case sensitive, even in case-insensitive databases.

    Caution

    For strongly encrypted databases, be sure to store a copy of the key in a safe location. If you lose the encryption key there is no way to access the data, even with the assistance of technical support. The database must be discarded and you must create a new database.

  • algorithm   This optional parameter specifies the algorithm originally used to encrypt the string-expression.

Returns

LONG BINARY

Remarks

For more information about the supported encryption algorithms, see ENCRYPT function [String].

You can use the DECRYPT function to decrypt a string-expression that was encrypted with the ENCRYPT function. This function returns a LONG BINARY value with the same number of bytes as the input string.

To successfully decrypt a string-expression, you must use the same encryption key that was used to encrypt the data. If you specify an incorrect encryption key, an error is generated. A lost key will result in inaccessible data, from which there is no recovery.

Note

FIPS is not available on all platforms. For a list of supported platforms, see [external link] http://www.sybase.com/detail?id=1061806.

See also
Standards and compatibility
  • SQL/2003   Vendor extension.

Example

The following example decrypts a user's password from the user_info table. The CAST function is used to convert the password back to a CHAR data type because the DECRYPT function converts values to the LONG BINARY data type, which is unreadable.

SELECT CAST( DECRYPT( user_pwd, '8U3dkA' ) AS CHAR(100) ) FROM user_info;