 |
Installing XP_CRYPT |
 |
XP_CRYPT API |
 |
Session |
 |
Asymmetric keys |
 |
DSA |
 |
RSA |
 |
DSA |
 |
RSA |
 |
Hashing |
 |
Symmetric encryption |
 |
AES128 |
 |
AES |
 |
DESX |
 |
RC4 |
 |
Triple DES |
 |
Tutorial |
 |
Troubleshooting |
|
This function uses a public key handle to encrypt data
Comparing to all previous versions XP_CRYPT 3.5 has the feature of " bulk
encryption". This means that from now it can encrypt not only VARCHAR
variables but also variables of all types (except TEXT and IMAGE ) and produce
one encrypted string which includes all variables. You can also encrypt NULL
and empty values. NOTE: All information decrypted with new xp_rsa_pub_enc
cannot be successfully decrypted with the older version. The older version will
output some garbage characters which in the new version are considered as controlling symbols.
Syntax
xp_rsa_pub_enc { variable1 [, variable2 , variable3 ...] , public_key_src,
encrypted_text OUTPUT}
Arguments
variable1 [, variable2 , variable3 ...]
Variables to be encrypted.
pubilc_key_src
VARCHAR. Source of the public key. It can be a handle, a filename or a key body.
encrypted_text
VARCHAR or VARBINARY. On success this variables holds the encrypted clear_text string. encrypted_text
should be big enough to store the result. For key length 256 bits and the string less
than 21 chars
the lengths
of the @encrypted_text variable should not be less than ~ 46 chars.
Permissions
Execute permissions default to the public role.
Return Code Values
0 - success, or Error code
if failed. encrypted_text IS NOT NULL (success) or IS NULL (failure)
Example
-- String encryption with previously loaded public
key or certificate
exec xp_rsa_load_key 'pubkey.pem', @PublicKey output
exec xp_rsa_pub_enc 'Hello, RSA!!!' , @PublicKey , @CryptedText output
exec xp_rsa_free_key @PublicKey
-- String encryption with key stored in .pem file. Key will be
loaded and freed automatically
exec xp_rsa_pub_enc 'Hello, RSA!!!' , '<pubkey.pem' , @CryptedText output
-- Shows new bulk encryption feature
declare @name as varchar (100)
declare @dateofbirth as datetime
declare @department int
declare @return_code int
select @name=name_field , @dateofbirth=dateofbirth_field ,
@department = department_field from employees
exec xp_rsa_pub_enc @name, @dateofbirth , @department , '<pubkey.pem' ,
@CryptedText output
-- @CryptedText contains the base64 encoded block of 3 fields
joined togather.
-- decrypt it now with the private key stored in 'privatekey.pem'
exec @return_code = xp_rsa_priv_dec @CryptedText, '<privatekey.pem', @name
OUTPUT, @dateofbirth OUTPUT , @department OUTPUT, 'PassForThePrivateKey'
|
|