发布网友 发布时间:2022-04-23 19:52
共2个回答
懂视网 时间:2022-05-01 04:13
declare
v2 varchar2(32); begin
v2 := Utl_Raw.Cast_To_Raw(sys.dbms_obfuscation_toolkit.md5(input_string => ‘111‘));
dbms_output.put_line(v2); end;
注意:可以在存储过程中直接调用,如果要嵌套调用md5时,记得每次调用后都用Utl_Raw.Cast_To_Raw进行转换,否则最后出来的结果是错误的。
2、构造函数后,再调用
代码如下:
CREATE OR REPLACE FUNCTION MD5(
passwd IN VARCHAR2) RETURN VARCHAR2 IS
retval varchar2(32); BEGIN
retval := utl_raw.cast_to_raw(DBMS_OBFUSCATION_TOOLKIT.MD5(INPUT_STRING => passwd)); RETURN retval; END;
调用md5函数示例:
代码如下:
select md5(1) from dual
另附:Oracle中MD5函数语句
代码如下:
--Oracle中MD5函数语句
create or replace FUNCTION "MD5HASH" (str IN VARCHAR2)
RETURN VARCHAR2
IS v_checksum VARCHAR2(32);
BEGIN
v_checksum := LOWER( RAWTOHEX( UTL_RAW.CAST_TO_RAW( sys.dbms_obfuscation_toolkit.md5(input_string => str) ) ) );
RETURN v_checksum;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise RAISE;
END md5hash;
Oracle中的MD5加密详解
标签:
热心网友 时间:2022-05-01 01:21
1、DBMS_OBFUSCATION_TOOLKIT.MD5是MD5编码的数据包函数
CREATE OR REPLACE FUNCTION MD5(passwd IN VARCHAR2)
RETURN VARCHAR2
IS
retval varchar2(32);
BEGIN
retval := utl_raw.cast_to_raw(DBMS_OBFUSCATION_TOOLKIT.MD5(INPUT_STRING => passwd)) ;
RETURN retval;
END;
select md5('123456') from al;
MD5('123456')
e10adc3949ba59abbe56e057f20f883e
2、DES加密
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;
DES加密:
update tb_salarysign_staff s set s.staffpwd =encrypt_des(s.staffpwd, 'test#5&124*!de');
3、DES解密函数
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;
DES解密:select decrypt_des(s.staffpwd, 'test#5&124*!de') from tb_salarysign_staff s;