oracle 12c masking,Oracle data masking

This problem is easily solved in 12c with the function STANDARD_HASH.

The solution in previous versions is only slightly more complicated. Build a simple wrapper around DBMS_CRYPTO that acts just like STANDARD_HASH:

--Imitation of the 12c function with the same name.

--Remember to drop this function when you upgrade!

create or replace function standard_hash(

p_string varchar2,

p_method varchar2 default 'SHA1'

) return varchar2 is

v_method number;

v_invalid_identifier exception;

pragma exception_init(v_invalid_identifier, -904);

begin

--Intentionally case-sensitive, just like the 12c version.

if p_method = 'SHA1' then

v_method := dbms_crypto.hash_sh1;

--These algorithms are only available in 12c and above.

$IF NOT DBMS_DB_VERSION.VER_LE_11 $THEN

elsif p_method = 'SHA256' then

v_method := dbms_crypto.hash_sh256;

elsif p_method = 'SHA384' then

v_method := dbms_crypto.hash_sh384;

elsif p_method = 'SHA512' then

v_method := dbms_crypto.hash_sh512;

$END

elsif p_method = 'MD5' then

v_method := dbms_crypto.hash_md5;

else

raise v_invalid_identifier;

end if;

return rawToHex(dbms_crypto.hash(utl_raw.cast_to_raw(p_string), v_method));

end;

/

You may need to logon with SYS and grant your user access to DBMS_CRYPTO to make the function work:

grant execute on sys.dbms_crypto to ;

Create a public synonym, grant it to everyone, and it works exactly the same way.

create public synonym standard_hash for .standard_hash;

grant execute on standard_hash to public;

select standard_hash('Some text', 'MD5') from dual;

9DB5682A4D778CA2CB79580BDB67083F

select standard_hash('Some text', 'md5') from dual;

ORA-00904: : invalid identifier

Here is a simple example of using the function:

update some_table

set column1 = standard_hash(column1),

column2 = standard_hash(column2);

But updating large amounts of data can be slow. It may be faster to create a new table, drop the old one, rename the new one, etc. And the hash value may be larger than the column size, it may be necessary to alter table some_table modify column1 varchar2(40 byte);

It amazes me how many products and tools there are to do such a simple thing.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值