Encrypt data in a table
1) Grant EXECUTE on DBMS_CRYPTO to UKIRAN;
2) Create or Replace package cryptit is
Function encrypt_data(p_data in VARCHAR2) Return RAW DETERMINISTIC;
Function decrypt_data(p_data in RAW) Return VARCHAR2 DETERMINISTIC;
END cryptit;
/
3) Create or Replace package body cryptit is
V_Key RAW(128) := UTL_RAW.cast_to_raw('testkey1');
Function encrypt_data(p_data IN VARCHAR2) Return RAW DETERMINISTIC
IS
l_data RAW(2048) := utl_raw.cast_to_raw(p_data);
l_encrypted RAW(2048);
BEGIN
NULL;
l_encrypted := dbms_crypto.encrypt
(src => l_data,
typ =>DBMS_CRYPTO.DES_CBC_PKCS5,
key => V_Key);
Return l_encrypted;
END encrypt_data;
Function decrypt_data(p_data in RAW) Return VARCHAR2 DETERMINISTIC
IS
l_decrypted RAW(2048);
BEGIN
l_decrypted := dbms_crypto.decrypt
(src => p_data,
typ =>DBMS_CRYPTO.DES_CBC_PKCS5,
key => V_KEY);
Return utl_raw.cast_to_varchar2(l_decrypted);
END decrypt_data;
END cryptit;
/
4) Update EMP set ENAME=cryptit.encrypt_data(ENAME);
Update CODE set NAME=cryptit.decrypt_data(NAME);
5) select * from CODE;
select cryptit.encrypt_data(NAME) NAME from CODE;
select cryptit.decrypt_data(NAME) NAME from CODE;
1) Grant EXECUTE on DBMS_CRYPTO to UKIRAN;
2) Create or Replace package cryptit is
Function encrypt_data(p_data in VARCHAR2) Return RAW DETERMINISTIC;
Function decrypt_data(p_data in RAW) Return VARCHAR2 DETERMINISTIC;
END cryptit;
/
3) Create or Replace package body cryptit is
V_Key RAW(128) := UTL_RAW.cast_to_raw('testkey1');
Function encrypt_data(p_data IN VARCHAR2) Return RAW DETERMINISTIC
IS
l_data RAW(2048) := utl_raw.cast_to_raw(p_data);
l_encrypted RAW(2048);
BEGIN
NULL;
l_encrypted := dbms_crypto.encrypt
(src => l_data,
typ =>DBMS_CRYPTO.DES_CBC_PKCS5,
key => V_Key);
Return l_encrypted;
END encrypt_data;
Function decrypt_data(p_data in RAW) Return VARCHAR2 DETERMINISTIC
IS
l_decrypted RAW(2048);
BEGIN
l_decrypted := dbms_crypto.decrypt
(src => p_data,
typ =>DBMS_CRYPTO.DES_CBC_PKCS5,
key => V_KEY);
Return utl_raw.cast_to_varchar2(l_decrypted);
END decrypt_data;
END cryptit;
/
4) Update EMP set ENAME=cryptit.encrypt_data(ENAME);
Update CODE set NAME=cryptit.decrypt_data(NAME);
5) select * from CODE;
select cryptit.encrypt_data(NAME) NAME from CODE;
select cryptit.decrypt_data(NAME) NAME from CODE;
No comments:
Post a Comment