Oracle Encryption and decryption ____oracle

Source: Internet
Author: User
Oracle Encryption and decryption

Cryptographic functions

Create or Replace function
Encrypt_des (P_text varchar2, P_key varchar2) return varchar2 is
V_text varchar2 (4000);
V_ENC varchar2 (4000);
Raw_input RAW (128);
Key_input RAW (128);
Decrypted_raw Raw (2048);
Begin
V_text: = Rpad (P_text, (trunc (Length (p_text)/8) +1) *8, Chr (0));
Raw_input: = Utl_raw. Cast_to_raw (V_text);
Key_input: = Utl_raw. Cast_to_raw (P_key);
Dbms_obfuscation_toolkit. Desencrypt (Input => raw_input,key => key_input,encrypted_data =>decrypted_raw);
V_enc: = Rawtohex (Decrypted_raw);
Dbms_output.put_line (V_ENC);
return v_enc;
End

Decryption function

Create or Replace function decrypt_des (p_text varchar2,p_key varchar2) return varchar2 is
V_text VARCHAR2 (2000);
Begin
Dbms_obfuscation_toolkit. Desdecrypt (input_string => Utl_raw. CAST_TO_VARCHAR2 (P_text), key_string =>p_key, decrypted_string=> v_text);
V_text: = RTrim (V_TEXT,CHR (0));
Dbms_output.put_line (V_text);
return v_text;
End

------------------------------------------------------------

Encryption

Select Encrypt_des (' Feng ', ' Test#5&124*!de ') from dual;

Input secret key: 15+5=17 result: B33f50ea2f5e23d7

Decrypt

Select Decrypt_des (' B33f50ea2f5e23d7 ', ' Test#5&124*!de ') from dual;

Input secret key: 15+5=17 result: Feng

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.