ORACLE應用經驗(4)-加密程式(轉)

Rounders發表於2007-08-09
ORACLE應用經驗(4)-加密程式[@more@]-------------1. 加密程式資料庫觸發子scjmmm----------------------
REM 對GHXXB制立資料庫觸發子(當INSERT OR UPDATE GHXXB時觸發)
drop trigger scjmmm;
create or replace trigger scjmmm
before insert or update of mm On ghxxb For each Row
Begin
:new.mm:=ENCRYPT(:new.mm,:NEW.GH,TO_CHAR(SYSDATE,'SS'));
End;
/
-------------2. 密碼的加密程式ENCRYPT----------------------
Create or Replace
Function ENCRYPT (Inpass In Varchar2,IN_GH In Varchar2,IN_SS In Varchar2)
Return Varchar2 Is
bcs varchar2(20);
bcs1 number;
cs number;
jg number;
m_gh VARCHAR2(4);
m_mm VARCHAR2(20);
Begin
m_gh:=IN_GH;
m_mm:=INPASS;
cs:=TO_NUMBER(IN_SS);
If cs<=1 then cs:=77 ;end if;
bcs:=substr(to_char(ascii(substr(m_gh,1,1))),1,2);
If bcs m_gh:=substr(m_gh,2);
Loop EXIT WHEN nvl(length(m_gh),0)=0 ;
bcs:=bcs||substr(to_char(ascii(substr(m_gh,1,1))),-1,1);
m_gh:=substr(m_gh,2);
End loop;
Loop EXIT WHEN nvl(length(m_mm),0)=0 ;
bcs:=bcs||substr(to_char(ascii(substr(m_mm,1,1))),-1,1);
m_mm:=substr(m_mm,2);
End loop;
bcs1:=to_number(bcs);
jg:=cs*bcs1;
Loop EXIT WHEN length(to_char(jg))>13;
jg:=jg*cs ;
End loop;
RETURN(IN_SS||substr(to_char(jg),1,14));
End;
/
grant execute on ENCRYPT to public;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9417382/viewspace-938095/,如需轉載,請註明出處,否則將追究法律責任。

相關文章