oracle 加密方案

create or replace function f_get_passboy_decode
(
  p_cfg_no Int  DEFAULT 0  --配置項編號
)
return HstypeChar256
as
  v_cfg_no              Int        := nvl(p_cfg_no,0);  --配置項編號
  v_result             Char2000;                       --返回結果值
  v_error_no           NumID;
  v_error_info         Char500;
  v_error_pathinfo     Char500;
  v_error_pathinfo_tmp Char500;                        --錯誤路徑臨時變量
    v_input VARCHAR2(100) := '12345678';
  v_key   VARCHAR2(100) := 'oracle9i';
  -- ORA-28232: obfuscation 工具箱的輸入長度無效(原因是加密字符串必須是8的倍數)

  encrypted_str VARCHAR2(4000);
  decrypted_str VARCHAR2(4000);
  encrypted_raw RAW(4000);
  decrypted_raw RAW(4000);
begin
  v_result  := '00' ;
  v_error_no  := 0 ;
  v_error_info  := ' ' ;
  v_error_pathinfo  := ' ' ;
  v_error_pathinfo := substr(v_error_pathinfo || '-->f_get_dm_config',1,500);
  v_error_pathinfo_tmp := v_error_pathinfo;


  -- string類型加密解密
  -- encrypt(string)
  dbms_obfuscation_toolkit.desencrypt(input_string => v_input, key_string => v_key, encrypted_string => encrypted_str);
  dbms_output.put_line('Encrypted string: ' || encrypted_str);
  dbms_output.put_line('Encrypted hex value: ' || utl_raw.cast_to_raw(encrypted_str));
  -- decrypt(string)
  dbms_obfuscation_toolkit.desdecrypt(input_string => encrypted_str, key_string => v_key, decrypted_string => decrypted_str);
  dbms_output.put_line('Decrypted String: ' || decrypted_str);

  -- raw類型加密解密
  -- encrypt(raw)
  dbms_obfuscation_toolkit.desencrypt(input => utl_raw.cast_to_raw(v_input), key => utl_raw.cast_to_raw(v_key), encrypted_data => encrypted_raw);
  dbms_output.put_line('Encrypted Raw: ' || encrypted_raw);
  dbms_output.put_line('Encrypted hex value: ' || rawtohex(encrypted_raw));
  -- decrypt(raw)
  dbms_obfuscation_toolkit.desdecrypt(input => encrypted_raw, key => utl_raw.cast_to_raw(v_key), decrypted_data => decrypted_raw);
  dbms_output.put_line('Decrypted String: ' || utl_raw.cast_to_varchar2(decrypted_raw));

select '000' into v_result from dual;
  return  v_result;
  exception when others then
    v_result := '0';

  return  v_result;

end f_get_passboy_decode;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章