3

永続的なマスクされた出力文字列を提供する Oracle 関数を使用して、特定のテーブル列をマスクする必要があります。

  • Oracle Hash Function を試してみましたが、String 型の戻り値が得られません。
  • Oracle Random 関数 (dbms_random.string) を試しましたが、永続的な出力文字列が得られません。

これは決定論的マスキングと呼ばれることをインターネットで読みました。しかし、Oracle Enterprise Manager は使用したくありません。ただし、直接 Oracle 関数が必要です。

提案してください。

4

4 に答える 4

4

この問題は、関数STANDARD_HASHを使用して 12c で簡単に解決できます。

以前のバージョンのソリューションは、少しだけ複雑です。STANDARD_HASH と同じように機能する DBMS_CRYPTO の単純なラッパーを作成します。

--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;
/

関数を機能させるには、SYS でログオンし、ユーザーに DBMS_CRYPTO へのアクセス権を付与する必要がある場合があります。

grant execute on sys.dbms_crypto to <your_schema>;

パブリック シノニムを作成し、全員に付与すると、まったく同じように機能します。

create public synonym standard_hash for <schema with function>.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

関数を使用する簡単な例を次に示します。

update some_table
set column1 = standard_hash(column1),
    column2 = standard_hash(column2);

ただし、大量のデータの更新は遅くなる可能性があります。新しいテーブルを作成し、古いテーブルを削除し、新しいテーブルの名前を変更するなどした方が速い場合があります。また、ハッシュ値が列のサイズよりも大きい場合があるため、必要になる場合があります。alter table some_table modify column1 varchar2(40 byte);

このような単純なことを行うための製品やツールがどれだけあるのかに驚かされます。

于 2014-03-22T01:54:50.933 に答える
0

本番データをマスクして、統合テストのために非本番データに移動するようなものがある場合。「ユーザー定義」関数の下にあると便利です。この機能は 10G 以上でのみ機能します。

create or replace function scrubbing(word in varchar2)
return varchar2
as
each_var char(2);
final_val varchar2(100);
complete_data varchar2(4000);
each_word varchar2(1000);
cursor val is select substr(replace(word,' ','#'),-level,1)  from dual connect by level<=length(word);
begin
open val;
--final_val:= '';
loop
    fetch val into each_var;
    exit when val%NOTFOUND;
    --dbms_output.put_line(each_var);
    final_val := trim(final_val)||trim(each_var);
    --dbms_output.put_line(final_val);
    select regexp_substr(final_val,'[A-Za-z]+') into each_word from dual;
    select replace(translate(final_val,each_word,dbms_random.string('L',length(word))),'#',' ') into complete_data from dual;
end loop;
return complete_data;
end;    
于 2016-05-10T11:50:42.417 に答える
-1

oracle の dbms_crpyto パッケージを使用できます。最初に varchar2 タイプを raw に変換し、次にハッシュ値に従ってデータをマスクする必要があります。

于 2018-06-12T12:12:32.183 に答える