Oracle 3DES Encryption Example

Source: Internet
Author: User

SET serveroutput on;declare input_string VARCHAR2 (32): = ' 12345678 ';  Ikey INTEGER: = 100001; Input_raw Raw (+): = Utl_raw.  Cast_to_raw (input_string);  Key_raw Raw (32);  Encrypted_raw Raw (32);  Encry_key VARCHAR2 (32); Decrypted_raw Raw (32);             BEGIN Key_raw: = Utl_raw.cast_from_binary_integer (ikey) | |  Utl_raw.bit_complement (Utl_raw.cast_from_binary_integer (Ikey)); Key_raw: = Key_raw | |  Utl_raw.bit_xor (Key_raw, Hextoraw (' f0f0f0f0f0f0f0f0 '));  Dbms_output.put_line (' > ========= Get Key Bytes ========= ');  Dbms_output.put_line (' > Input String: ' | | input_string);  Dbms_output.put_line (' > Key String: ' | | key_raw); Dbms_output.put_line (' > Key length: ' | |  Utl_raw.length (Key_raw));  Dbms_output.put_line (' > ========= BEGIN TEST Encrypt ========= '); --Encryption Encrypted_raw: = Dbms_obfuscation_toolkit.                                 Des3encrypt (input = input_raw, key = Key_raw,                       IV = Hextoraw (' 0000000000000000 '));  Dbms_output.put_line (' > Encrypted_raw output: ' | | encrypted_raw);  Encry_key: = Utl_raw.cast_to_varchar2 (Utl_encode.base64_encode (Encrypted_raw));    Dbms_output.put_line (' > Encry_key output: ' | | encry_key); --Decrypt Decrypted_raw: = Dbms_obfuscation_toolkit.                                                        Des3decrypt (input = encrypted_raw, key = Key_raw,  IV = Hextoraw (' 0000000000000000 '));  Dbms_output.put_line (' > Decrypted_raw output: ' | | utl_raw.cast_to_varchar2 (DECRYPTED_RAW)); IF input_string = utl_raw.cast_to_varchar2 (Decrypted_raw) then Dbms_output.put_line (' > String DES encyption and DECR  Yption successful '); END IF; end;/

Shown below:

> ========= Get Key Bytes =========
> Input string:12345678
> Key string:000186a1fffe795ef0f176510f0e89ae
> Key length:16
> ========= BEGIN TEST Encrypt =========
> Encrypted_raw output:9d2a9569d15a07db
> Encry_key output:nsqvadfab9s=
> Decrypted_raw output:12345678
> String DES encyption and decryption successful
PL/SQL procedure successfully completed

Oracle 3DES Encryption Example

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.