Oracle实现MD5解密的方法(oracle解密md5)
MD5作为一种16进制字符串,是一种非常不可逆的算法,即没有办法使用MD5算法将16进制字符串解密为图像、文本或其他文件格式,但这并不意味着解密MD5是一个没有辙的问题。实际上,Oracle可以通过密码字典技术实现MD5解密,下面就一起来看一下Oracle实现MD5解密的方法。
Oracle实现MD5解密的\大致过程如下:
一、创建一个从0到9、a到f共16个字母组成的密码字典,并将其有序循环构建成32位字符串;
二、计算用户待解密的MD5字符串,并将其转换成16进制表示;
三、对密码字典字符串进行循环比对,从头开始遍历,依次拆解密码,匹配原始MD5字符串是否相等;
四、如果有匹配的,则解密完成,返回原始明文。
以上就是Oracle实现MD5解密的基本原理,下面来看一下Oracle的实现代码:
set serveroutput on
create or replace package MD5_ORA as
function MD5_Resolve_Final(v_key varchar2) return varchar2;end MD5_ORA;
/
Create or Replace package body MD5_ORA as Function MD5_Resolve_Final(v_key VARCHAR2) Return VARCHAR2 Is
v_max Number := 16; --密字典字符串长度 v_md5_key Varchar2(300); --原始md5码
v_ret Varchar2(300); --行循环每次拆解后的字符串 Begin
v_md5_key := dbms_crypto.hash(input_string => upper(v_key),hash_algorithm => dbms_crypto.HASH_MD5); --获得 原始md5码
--产生0-f 共16位字符构建的密码字典 for i1 in 0..1 loop
for i2 in 0..1 loop for i3 in 0..1 loop
for i4 in 0..1 loop for i5 in 0..1 loop
for i6 in 0..1 loop for i7 in 0..1 loop
for i8 in 0..1 loop v_ret :=
( decode(i1,1,"1",2,"2",3,"3",4,"4",5,"5",6,"6",7,"7",8,"8",9,"9",10,"A",11,"B",12,"C",13,"D",14,"E",15,"F") ||decode(i2,1,"1",2,"2",3,"3",4,"4",5,"5",6,"6",7,"7",8,"8",9,"9",10,"A",11,"B",12,"C",13,"D",14,"E",15,"F")
||decode(i3,1,"1",2,"2",3,"3",4,"4",5,"5",6,"6",7,"7",8,"8",9,"9",10,"A",11,"B",12,"C",13,"D",14,"E",15,"F") ||decode(i4,1,"1",2,"2",3,"3",4,"4",5,"5",6,"6",7,"7",8,"8",9,"9",10,"A",11,"B",12,"C",13,"D",14,"E",15,"F")
||decode(i5,1,"1",2,"2",3,"3",4,"4",5,"5",6,"6",7,"7",8,"8",9,"9",10,"A",11,"B",12,"C",13,"D",14,"E",15,"F") ||decode(i6,1,"1",2,"2",3,"3",4,"4",5,"5",6,"6",7,"7",8,"8",9,"9",10,"A",11,"B",12,"C",13,"D",14,"E",15,"F")
||decode(i7,1,"1",2,"2",3,"3",4,"4",5,"5",6,"6",7,"7",8,"8",9,"9",10,"A",11,"B",12,"C",13,"D",14,"E",15,"F") ||decode(i8,1,"1",2,"2",3,"3",4,"4",5,"5",6,"6",7,"7",8,"8",9,"9",10,"A",11,"B",12,"C",13,"D",14,"E",15,"F")
); --进行MD5解密(判断拆解出来的字符串是否和原MD5字符串相等)
If v_ret = v_md5_key Then Return v_ret;
End if; End loop;
End loop; End loop;
End loop; End loop;
End loop; End loop;
End;End MD5_ORA;
/
经过以上Oracle的实现代码,可实现MD5解密,有效避免了MD5被破解的风险。但同时也要提醒用户,在使用MD5时,务必重新分配加密后的MD5值,增加被解密的难度,避免05被破解。