sql - Trouble With Encryption in Oracle11g -
i working on lab attempting encrypt dummy ssn , provide output in sql plus shows unencrypted ssn, encrypted ssn, , decrypted ssn.
the value encrypting 555 55 5555, decrypted value appears 33353335333532303335333532303335333533353335. i'm not quite issue lies, since appears @ least decryption occurring. suggestions appreciated. sql below
set serveroutput on declare ssn varchar2(200) := '555 55 5555'; ssn_decrypt varchar(200); ssn_raw raw (200) := utl_raw.cast_to_raw(ssn); num_key_bytes number := 256/8; key_bytes_raw raw (32); encryption_type pls_integer := dbms_crypto.encrypt_aes256 + dbms_crypto.chain_cbc + dbms_crypto.pad_pkcs5; encrypted_raw raw (2000); decrypted_raw raw(2000); begin dbms_output.put_line('the unencrypted ssn is: ' || ssn); key_bytes_raw := dbms_crypto.randombytes (num_key_bytes); encrypted_raw := dbms_crypto.encrypt ( utl_i18n.string_to_raw (ssn), typ => encryption_type, key => key_bytes_raw ); decrypted_raw := dbms_crypto.decrypt ( src => encrypted_raw, typ => encryption_type, key => key_bytes_raw ); ssn_decrypt := utl_i18n.raw_to_char (decrypted_raw, '555 55 5555'); dbms_output.put_line('the encrypted ssn is: ' || rawtohex(utl_raw.cast_to_raw(encrypted_raw))); dbms_output.put_line('the decrypted ssn is:' || rawtohex(utl_raw.cast_to_raw(decrypted_raw))); end; /
the example found dbms_crypto
documentation works flawlessly. copy , you'll good.
one issue don't define correct parameters in char vs. raw conversions. should be:
utl_i18n.string_to_raw(ssn, 'al32utf8') utl_i18n.raw_to_char(decrypted_raw, 'al32utf8');
note example assumes database character set al32utf8. if not have make conversion too.
Comments
Post a Comment