0% found this document useful (0 votes)
2 views2 pages

Oracle AES Encryption and Decryption Functions

The document contains two PL/SQL functions for encryption and decryption using AES-128 in CBC mode with PKCS5 padding. The 'decrypt' function takes an encrypted string and returns the decrypted string, while the 'encrypt' function takes a plain string and returns its encrypted RAW format. Both functions utilize a predefined key for the encryption and decryption processes.

Uploaded by

Awais Aslam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Oracle AES Encryption and Decryption Functions

The document contains two PL/SQL functions for encryption and decryption using AES-128 in CBC mode with PKCS5 padding. The 'decrypt' function takes an encrypted string and returns the decrypted string, while the 'encrypt' function takes a plain string and returns its encrypted RAW format. Both functions utilize a predefined key for the encryption and decryption processes.

Uploaded by

Awais Aslam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

create or replace FUNCTION decrypt(p_string VARCHAR2)

RETURN VARCHAR2 AS
l_key VARCHAR2 (2000) := '1234567890999899';
l_mod NUMBER
:= dbms_crypto.encrypt_aes128
+ dbms_crypto.chain_cbc
+ dbms_crypto.pad_pkcs5;
l_decrypted_raw RAW (2000);
l_decrypted_string VARCHAR2(2000);
BEGIN
l_decrypted_raw :=
dbms_crypto.decrypt (p_string,
l_mod,
utl_i18n.string_to_raw (l_key, 'AL32UTF8'));
l_decrypted_string := utl_i18n.raw_to_char (l_decrypted_raw);

--DBMS_OUTPUT.put_line ('Decrypted=' || UTL_I18N.raw_to_char (l_decrypted_raw));

RETURN l_decrypted_string;
END decrypt;

create or replace FUNCTION encrypt (p_string VARCHAR2)


RETURN RAW AS
l_key VARCHAR2 (2000) := '1234567890999899';
l_mod NUMBER
:= dbms_crypto.encrypt_aes128
+ dbms_crypto.chain_cbc
+ dbms_crypto.pad_pkcs5;
l_encrypted_raw RAW (2000);
l_return RAW (2000);
BEGIN
l_encrypted_raw :=
dbms_crypto.encrypt (utl_i18n.string_to_raw (p_string, 'AL32UTF8'),
l_mod,
utl_i18n.string_to_raw (l_key, 'AL32UTF8'));

-- dbms_output.put_line ('Encrypted=' || l_encrypted_raw);

RETURN l_encrypted_raw;
END encrypt;

You might also like