xp_aes_encrypt
Encrypts data with the given key by AES algorithm.
Syntax
xp_aes_encrypt { variable1 [, variable2 ,
variable3 ...] , key, encrypted_text OUTPUT }
Arguments
variable1 [, variable2 , variable3 ...]
Variables which need to be encrypted
key
VARCHAR. The key is represented by a string which consists of
characters from 0 to 9 and A, B, C, D, E, F so called 'hexadecimal
notation'.The valid lengths of the string are 32, 48 and 64 chars. This
involves the encryption with 128, 196 and 256 bit key. Example of 32 chars
key - '076541A84BEF792A1234567890D98769'
clear_text
VARCHAR or VARBINARY. Variable to hold the encrypted output
Permissions
Execute permissions default to the public role.
Return Code Values
0 - success, or Error code if failed. clear_text
IS NOT NULL (success) or IS NULL (failure)
Example
declare @encrypted varchar (8000)
declare @return_code int
exec xp_aes_encrypt
'test','0123456789ABCDEF0123456789ABCDEF',@encrypted output
exec @return_code = xp_aes_decrypt
@a,'0123456789ABCDEF0123456789ABCDEF',@encrypted output
if @return_code != 0
begin
raiserror ('AES encryption failed!',16,10)
end |
|