Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

decrypt from table

RobeenFeb 1 2021

Oracle DB 12.1.0.2
Hello Team,
how do I use the function below to decrypt data from a table?
DECLARE
input_string VARCHAR2 (200) := 'Secret Message';
output_string VARCHAR2 (200);
encrypted_raw RAW (2000); -- stores encrypted binary text
decrypted_raw RAW (2000); -- stores decrypted binary text
num_key_bytes NUMBER := 256/8; -- key length 256 bits (32 bytes)
key_bytes_raw RAW (32); -- stores 256-bit encryption key
encryption_type PLS_INTEGER := -- total encryption type
DBMS_CRYPTO.ENCRYPT_AES256
+ DBMS_CRYPTO.CHAIN_CBC
+ DBMS_CRYPTO.PAD_PKCS5;
BEGIN
DBMS_OUTPUT.PUT_LINE ( 'Original string: ' || input_string);
key_bytes_raw := DBMS_CRYPTO.RANDOMBYTES (num_key_bytes);
encrypted_raw := DBMS_CRYPTO.ENCRYPT
(
src => UTL_I18N.STRING_TO_RAW (input_string, 'AL32UTF8'),
typ => encryption_type,
key => key_bytes_raw
);
-- The encrypted value "encrypted_raw" can be used here

decrypted_raw := DBMS_CRYPTO.DECRYPT
(
src => encrypted_raw,
typ => encryption_type,
key => key_bytes_raw
);
output_string := UTL_I18N.RAW_TO_CHAR (decrypted_raw, 'AL32UTF8');

DBMS_OUTPUT.PUT_LINE ('Decrypted string: ' || output_string);
END;

As shown below, we would like to decrypt ID_DOC_NUM from table below.
image.pngThe only information we have about the encryption and decryption mechanism:
. Encrypt & decrypt Methodology & Key
a) We are using code base 64 and ASE128 to do the decrypt data
b) We are calling in DB function in java to do decrypt & encrypt.

Refeence: https://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_crypto.htm#i1001225

Thanks,

Roshan

This post has been answered by Robeen on Feb 3 2021
Jump to Answer
Comments
Post Details
Added on Feb 1 2021
6 comments
2,052 views