Nov 24, 2008

Encryption

CREATE OR REPLACE FUNCTION fnc_encryption(pi_src IN VARCHAR2) RETURN CLOB
IS
v_enc_val raw(32767);
v_key1 VARCHAR2(16) := '1111111111111111';
v_key2 VARCHAR2(16) := '2222222222222222';
v_charterset VARCHAR2(8) := 'AL32UTF8';
v_mod number := DBMS_CRYPTO.ENCRYPT_AES128
+ DBMS_CRYPTO.CHAIN_CBC
+ DBMS_CRYPTO.PAD_PKCS5;
BEGIN
v_enc_val := DBMS_CRYPTO.ENCRYPT(
src => UTL_I18N.STRING_TO_RAW(pi_src, v_charterset),
typ => v_mod,
key => UTL_I18N.STRING_TO_RAW(v_key1, v_charterset),
iv => UTL_I18N.STRING_TO_RAW(v_key2, v_charterset)
);
RETURN RAWTOHEX(v_enc_val);
END fnc_encryption;
/



Scenario 1: Use the function to encrypt all of the rows in the table and then repeat the operation - no error occurs:

SQL> update TEST
2 SET NAME=fnc_encryption(name);

3 rows updated.

SQL> update TEST
2 SET NAME=fnc_encryption(name);

3 rows updated.

No comments: