首先以 sys 用户授权执行 dbms_crypto 包:
grant execute on sys.dbms_crypto to yphoa;
创建一张表,有两个字段,一个字段是要码数据的id,别一个字段是加密key
加密方法:
create or replace function initbudgetencrypt(p_key in varchar2, p_in in varchar2) return raw is encrypted_raw raw(4000); encryption_type pls_integer := dbms_crypto.encrypt_aes128 + dbms_crypto.chain_cbc + dbms_crypto.pad_pkcs5; begin encrypted_raw := dbms_crypto.encrypt(src => utl_i18n.string_to_raw(p_in,'al32utf8'), typ => encryption_type, key => p_key); return encrypted_raw; end; 解密方法: create or replace function initbudgettest(p_key in varchar2, p_in in raw) return varchar2 is output_string varchar2(4000); decrypted_raw raw(4000); encryption_type pls_integer := dbms_crypto.encrypt_aes128 + dbms_crypto.chain_cbc + dbms_crypto.pad_pkcs5; begin decrypted_raw := dbms_crypto.decrypt(src => p_in, typ => encryption_type, key => p_key); output_string := utl_i18n.raw_to_char(decrypted_raw, 'al32utf8'); return output_string; end;