SQL> CONN SYS/SYS AS SYSDBA
Connected.
SQL> set serveroutput on
SQL>
SQL> set linesize 121
SQL>
SQL> DECLARE
l_credit_card_no VARCHAR2(19) := ‘1234-5678-9012-3456’;
l_ccn_raw RAW(128) := utl_raw.cast_to_raw(l_credit_card_no);
l_key RAW(128) := utl_raw.cast_to_raw(‘abcdefgh’);
l_encrypted_raw RAW(2048);
l_decrypted_raw RAW(2048);
BEGIN
dbms_output.put_line(‘Original : ‘ || l_credit_card_no);

l_encrypted_raw := dbms_crypto.encrypt(l_ccn_raw,
dbms_crypto.des_cbc_pkcs5, l_key);

dbms_output.put_line(‘Encrypted : ‘ ||
RAWTOHEX(utl_raw.cast_to_raw(l_encrypted_raw)));

l_decrypted_raw := dbms_crypto.decrypt(src => l_encrypted_raw,
typ => dbms_crypto.des_cbc_pkcs5, key => l_key);

dbms_output.put_line(‘Decrypted : ‘ ||
utl_raw.cast_to_varchar2(l_decrypted_raw));
END;
/
Original : 1234-5678-9012-3456
Encrypted : 38303843354144343732323245303145433338393341423337343543464345393641
3643354144344245454345424136
Decrypted : 1234-5678-9012-3456

PL/SQL procedure successfully completed.

Leave a Reply

Your email address will not be published. Required fields are marked *