Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: encryption of strings
Michael Rothwell wrote:
>
> Do you have an example of this code? I would be curious to see it.
>
> Thanks
>
> Michael.
>
> Connor McDonald wrote:
>
> > Clinique wrote:
> > >
> > > Hi everybody,
> > > I am searching for a possibility to encrypt string data types which serve as
> > > passwords in a database table for user management.
> > > Does Oracle offer some kind of procedure for encryption?
> > > Susanne
> >
> > Have a look at Thomas's solution...If you require DE-cryption as well as
> > encryption, you can try the following:
> >
> > Have a (secret) key of (say) 30 chars
> > For each char in string
> > - get ascii val of char
> > - get ascii val of i'th char in key
> > - exclusive-or the two values
> > - chr() the resultant value - this is the 'encrypted' char
> >
> > The resultant encryted string is relatively difficuly to break. To
> > decrypt, just run encyrption again.
> >
> > HTH
> > --
> > ===========================================
> > Connor McDonald
> > http://www.oracledba.co.uk
> >
> > We are born naked, wet and hungry...then things get worse
I don't have the code with me, but off the cuff (ie full of compile errors I suspect):
procedure encode(p_string varchar2, p_code out varchar2) is
v_key varchar2(60) := 'My secret key'; v_result varchar2(500); v_each_byte number(3); v_each_key_byte number(3);
-- -- Make sure the key is at least 30 chars long -- while length(v_key) < 30 loop v_key := v_key || v_key; end loop; v_key := substr(v_key,1,30); -- -- For each char in the string -- for i in 1 .. length(p_string) loop -- -- get the ascii vals of the char, and its equivalent in the key -- v_each_byte := ascii(substr(p_string,i,1)); v_each_key_byte := ascii(substr(v_key,mod(i,30)+1,1)); -- -- xor the two ascii values and convert back to a char byte -- v_result := v_result || chr(v_each_byte + v_each_key_byte - bitand(v_each_byte,v_each_key_byte)); end loop; p_code := v_result; end; Naturally you would want to wrap the PL/SQL so that no-one can see your key. HTH -- =========================================== Connor McDonald http://www.oracledba.co.uk We are born naked, wet and hungry...then things get worseReceived on Wed Jun 14 2000 - 00:00:00 CDT
![]() |
![]() |