This content has been marked as final. Show 2 replies
In general, you can't get different results in different environments, no.
You could, of course, write your decrypt routine so that it catches the exception and returns a random RAW string.
However, this is not normally the way people go about masking sensitive data in lower environments. It would be much more common to use a tool that is designed for this tool. For example, Oracle has a Data Masking Pack for Enterprise Manager that can be used as part of the refresh of lower environments to replace sensitive data with fake but realistic data. There are also third-party data masking tools like Data Masker.
If I understand what you are trying to do ... and I may not ... it is not going to work.
SQL> DECLARE 2 l_credit_card_no VARCHAR2(19) := '1612-1791-1809-2605'; 3 l_ccn_raw RAW(128) := utl_raw.cast_to_raw(l_credit_card_no); 4 l_key1 RAW(128) := utl_raw.cast_to_raw('abcdefgh'); 5 l_key2 RAW(128) := utl_raw.cast_to_raw('zyxwvuts'); -- alternate key used to attempt a different decryption 6 7 l_encrypted_raw RAW(2048); 8 l_decrypted_raw RAW(2048); 9 BEGIN 10 dbms_output.put_line('Original : ' || l_credit_card_no); 11 12 l_encrypted_raw := dbms_crypto.encrypt(l_ccn_raw, dbms_crypto.des_cbc_pkcs5, l_key1); 13 14 dbms_output.put_line('Encrypted : ' || RAWTOHEX(utl_raw.cast_to_raw(l_encrypted_raw))); 15 16 l_decrypted_raw := dbms_crypto.decrypt(src => l_encrypted_raw, typ => dbms_crypto.des_cbc_pkc s5, key => l_key1); 17 18 dbms_output.put_line('Key1 : ' || utl_raw.cast_to_varchar2(l_decrypted_raw)); 19 20 l_decrypted_raw := dbms_crypto.decrypt(src => l_encrypted_raw, typ => dbms_crypto.des_cbc_pkc s5, key => l_key2); 21 22 dbms_output.put_line('Key2 : ' || utl_raw.cast_to_varchar2(l_decrypted_raw)); 23 END; 24 / Original : 1612-1791-1809-2605 Encrypted : 3534443342333642353141363846384237463732384636373943374630364234323243334539383042323135 Key1 : 1612-1791-1809-2605 DECLARE * ERROR at line 1: ORA-28817: PL/SQL function returned an error. ORA-06512: at "SYS.DBMS_CRYPTO_FFI", line 67 ORA-06512: at "SYS.DBMS_CRYPTO", line 44 ORA-06512: at line 20