|
The function loads a private key, a public key or x.509 certificate from a file or
string into memory.
Syntax
xp_rsa_load_key { key_source, key_handle OUTPUT [, password]
}
Arguments
key_source
VARCHAR. The source of the key to be loaded. There are 3 types of key
source:
- Handle: Handle of the key which is already loaded into memory. A key of
this type cannot be used here as a key source. A key handle is returned as a result of
the successful
loading. Using handles significantly increases speed of the encryption/decryption operation comparing to filename of key bodies. One
disadvantage is that you should explicitly free the key after the usage.
The use of the filename or body as a source does not require xp_rsa_free_key
function, they are loaded and freed automatically.
- Filename: This is a default source of the key. You can simply specify
the name of the file here or precede it with '<' character. In the other
functions you must explicitly precede file names. Keys can be stored in PEM or
x.509 format.
- Key body: This is the VARCHAR string which holds the content of the
key file. Sometimes it is very useful when you do not need to store keys
at the server side and simply load them from your client connection. In
this case your front end software must read a key file and pass its
content as a string. You must preserve new lines and all semantic in
this file.
key_handle
VARCHAR. This variable receives the handle of the loaded key. This key
handle refers to the real key loaded into
memory and only valid until you explicitly free it with xp_rsa_free_key
or restart the server. Declare the key variable as varchar (20).
password
VARCHAR. A password which is used for loading the key from the source. Do not provide passwords for the
public keys or certificates. If password is given, the key is considered as private
one. Otherwise xp_rsa_load_key will attempt to load the public key or x.509
certificate. If the pswd_cache option is set to yes and the given
password is '?' XP_CRYPT will try to load the key with a 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. key_handle IS NOT NULL (success) or key_handle IS NULL (failure)
Example
-- Loading private key from file
exec xp_rsa_load_key 'privkey.pem', @PrivateKey output, 'SecurePassword'
-- Loading public key or certificate from file
exec xp_rsa_load_key 'pubkey.pem', @PubKey output |
|