DECRYPT¶
The DECRYPT
function or procedure decrypts data using a user-specified
cipher algorithm, key and optional initialization vector. The signature of the DECRYPT
function is:
DECRYPT
(<src> IN RAW, <typ> IN INTEGER, <key> IN RAW, <iv> IN RAW
DEFAULT NULL) RETURN RAW
The signature of the DECRYPT
procedure is:
DECRYPT
(<dst> INOUT BLOB, <src> IN BLOB, <typ> IN INTEGER, <key> IN RAW,
<iv> IN RAW DEFAULT NULL)
or
DECRYPT
(<dst> INOUT CLOB, <src> IN CLOB, <typ> IN INTEGER, <key> IN RAW,
<iv> IN RAW DEFAULT NULL)
When invoked as a procedure, DECRYPT
returns BLOB
or CLOB
data to a
user-specified BLOB
.
Parameters
dst
dst
specifies the name of aBLOB
to which the output of theDECRYPT
procedure will be written. TheDECRYPT
procedure will overwrite any existing data currently indst
.
src
src
specifies the source data that will be decrypted. If you are invokingDECRYPT
as a function, specifyRAW
data; if invokingDECRYPT
as a procedure, specifyBLOB
orCLOB
data.
typ
typ
specifies the block cipher type and any modifiers. This should match the type specified when thesrc
was encrypted. Advanced Server supports the following block cipher algorithms, modifiers and cipher suites:
Block Cipher Algorithms |
|
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Block Cipher Modifiers |
|
|
|
|
|
Block Cipher Padding Modifiers |
|
|
|
|
|
Block Cipher Suites |
|
|
|
|
|
|
|
key
key
specifies the user-defined decryption key. This should match the key specified when thesrc
was encrypted.
iv
iv
(optional) specifies an initialization vector. If an initialization vector was specified when thesrc
was encrypted, you must specify an initialization vector when decrypting thesrc
. The default isNULL
.
Examples
The following example uses the DBMS_CRYPTO.DECRYPT
function to decrypt
an encrypted password retrieved from the passwords
table:
CREATE TABLE passwords
(
principal VARCHAR2(90) PRIMARY KEY, -- username
ciphertext RAW(9) -- encrypted password
);
CREATE FUNCTION get_password(username VARCHAR2) RETURN RAW AS
typ INTEGER := DBMS_CRYPTO.DES_CBC_PKCS5;
key RAW(128) := 'my secret key';
iv RAW(100) := 'my initialization vector';
password RAW(2048);
BEGIN
SELECT ciphertext INTO password FROM passwords WHERE principal = username;
RETURN dbms_crypto.decrypt(password, typ, key, iv);
END;
Note that when calling DECRYPT
, you must pass the same cipher type, key
value and initialization vector that was used when ENCRYPTING
the
target.