• Oracle 3DES加密示例


    SET SERVEROUTPUT ON;
    DECLARE
      input_string  VARCHAR2(32) := '12345678';
      ikey          INTEGER := 100001;
      input_raw     RAW(32) := 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 =========');
      --加密
      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);
      
      --解密
      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 Decryption successful');
      END IF;
    END;
    /
    

    显示如下:

    > ========= 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

  • 相关阅读:
    2020-02-26 今天学了啥?
    2020-02-25 今天学了啥?
    CSS选择器世界
    2019.12.21---今天学了啥?
    2019.12.20--今天学了啥?
    2019.12.19----今天学了啥?
    重拾算法之复杂度分析(大O表示法)
    es6之后,真的不需要知道原型链了吗?
    你真的了解FastClick吗?
    JavaScript中的对象与原型—你不知道的JavaScript上卷读书笔记(四)
  • 原文地址:https://www.cnblogs.com/wqswjx/p/5458837.html
Copyright © 2020-2023  润新知