How to use Encryption and Decryption concepts in PL/SQL?
858277Jul 5 2011 — edited Jan 11 2013Hi ,
I was tried to know about the Encryption and Decryption concepts in PL/SQL using functions, but am getting the following.
Can anyone please help me to know about this and to resolve?
I have binded the ERROR with written function.
DECLARE
input_string VARCHAR2 (200) := 'Secret Message';
output_string VARCHAR2 (200);
encrypted_raw RAW (2000);
decrypted_raw RAW (2000);
num_key_bytes NUMBER := 256/8;
KEY_BYTES_RAW RAW (32);
encryption_type PLS_INTEGER := 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;
Error report:
ORA-06550: line 8, column 38:
PLS-00201: identifier 'DBMS_CRYPTO' must be declared
ORA-06550: line 8, column 23:
PL/SQL: Item ignored
ORA-06550: line 11, column 21:
PLS-00201: identifier 'DBMS_CRYPTO' must be declared
ORA-06550: line 11, column 4:
PL/SQL: Statement ignored
ORA-06550: line 12, column 21:
PLS-00201: identifier 'DBMS_CRYPTO' must be declared
ORA-06550: line 12, column 4:
PL/SQL: Statement ignored
ORA-06550: line 20, column 21:
PLS-00201: identifier 'DBMS_CRYPTO' must be declared
ORA-06550: line 20, column 4:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action: