|
This function uses the private key handle to sign the
data. To verify the signature use xp_dsa_verify.
XP_CRYPT makes DSA-SHA1 signature. For this operation the keys that are
longer than 512 bytes are required. If you use the demo version of
XP_CRYPT you cannot generate keys longer than 256 bits. The free
version contains 2 pre-generated keys: publickey512.pem and
privatekey512.pem. You can use them for testing. The password for the
private key is xp_crypt.
Syntax
xp_dsa_sign { variable1 [, variable2 , variable3 ...]
, private_key_src, signature OUTPUT, [src_password]}
Arguments
variable1 [, variable2 , variable3 ...]
One or more variables to sign. The order of the variables is
important. If you put the same variables in another order the
digital sign will be completely different.
private_key_src
VARCHAR. Source of the private key. It can be a handle, a filename or a key body.
signature
VARCHAR or VARBINARY. A unique signature value for this set of variables. The
output length of this variable does not depend on the amount of data you
sign, but only on the size of the key you use.
src_password
VARCHAR. A password for reading the key if its source is in the file
of key string. If the pswd_cache option is set to yes
and the given password is '?' XP_CRYPT will try to load the
key with the password stored in the session. See xp_crypt_set_option for more
information about pswd_cache option.
Permissions
Execute permissions default to the public role.
Return Code Values
0 - success, or Error code if failed.
Signature IS NOT NULL (success) or IS NULL (failure)
Example
|
-- String signing with key stored in .pem file. Key will be
loaded and freed automatically
exec xp_dsa_sign 'Show must go on' , '<pubkey.pem' , @sign
OUTPUT
-- Shows new bulk encryption feature
declare @name as varchar (100)
declare @dateofbirth as datetime
declare @department int
declare @sign VARCHAR(8000)
select @name=name_field , @dateofbirth=dateofbirth_field ,
@department = department_field from employees
exec xp_dsa_sign @name, @dateofbirth , @department ,
'<privatekey.pem' , @sign output, 'MyPassword'
-- @sign contains the base64 encoded sign of 3 fields joined
together. If you modify any of those fields xp_dsa_verify
will fail
-- Let's check the signature
exec xp_dsa_verify @name, @dateofbirth , @department ,
'<publickey.pem', @sign , @result OUTPUT
if @result is not null and @result = 1
begin
-- Exactly this variables was signed by our private key!
...
else
-- Someone has altered our data ! Probably it is not valid !
...
end
|
|