• Oracle列加密


    加密函数

    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;

    解密函数

    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;


    加密


    SQL> select encrypt_des('liang', 'xssssxxsese') from dual;

    ENCRYPT_DES('LIANG','XSSSSXXSESE')
    --------------------------------------------------------------------------------
    5DC5AC97C81ECEEF

    解密
    SQL> select decrypt_des('5DC5AC97C81ECEEF', 'xssssxxsese') from dual;

    DECRYPT_DES('5DC5AC97C81ECEEF','XSSSSXXSESE')
    --------------------------------------------------------------------------------
    liang

    create table test_des (id int ,passwd varchar2(200));
    insert into test_des values (1,encrypt_des('liang', 'xssssxxsese'));

    SQL> select * from test_des;

    ID PASSWD
    ---------- --------------------
    1 5DC5AC97C81ECEEF

    SQL> select id,decrypt_des(passwd, 'xssssxxsese') from test_des;

    ID DECRYPT_DES(PASSWD,'XSSSSXXSESE')
    ---------- ---------------------------------------
    1 liang




  • 相关阅读:
    人民币大小写转换
    清除vs中的最近打开的项目列表
    OWC绘图控件研究
    Fat32的磁盘格式转成Ntfs磁盘格式
    Host "localhost " is not allowed to connect to mysql server解决方法
    OWC中组合图的开发(柱状图+折线图)
    mysql 1251错误解决方法
    使用OWC做统计图图标样式
    完全卸载MYSQL
    nginx 伪静态
  • 原文地址:https://www.cnblogs.com/l10n/p/9103524.html
Copyright © 2020-2023  润新知