Home » SQL & PL/SQL » SQL & PL/SQL » how to decrypt data in oracle 8.0
how to decrypt data in oracle 8.0 [message #35606] Mon, 01 October 2001 03:16 Go to next message
Sangeeta
Messages: 9
Registered: October 2001
Junior Member
hello,

i need to encrypt the passwords stored in a table.
i created the following function to encrypt the password and then invpoked this function using a trigger each time a user inserted or updated the password.
here is the code
****************
create or replace function digest( p_username in varchar2, p_password in varchar2 ) return varchar2
is
begin
return ltrim( dbms_utility.get_hash_value( upper(p_username)||'erdci'||upper(p_password),
10000000, power(2,30)) );
end digest;

this code encrypts my data but now the problem is how to decrypt it.

can anyone help????????

----------------------------------------------------------------------
Re: how to decrypt data in oracle 8.0 [message #35688 is a reply to message #35606] Fri, 05 October 2001 15:41 Go to previous messageGo to next message
Ralph
Messages: 4
Registered: October 2001
Junior Member
LOL. At first I thought this post was a joke.
Why would you invent an encrytion routine with no plan for decryption? Try looking into Oracle's dbms_obfuscation_toolkit package. They make both methods available.

----------------------------------------------------------------------
Re: how to decrypt data in oracle 8.0 [message #35699 is a reply to message #35688] Sun, 07 October 2001 20:27 Go to previous messageGo to next message
Sangeeta
Messages: 9
Registered: October 2001
Junior Member
i am aware of the dbms_obfuscation_toolkit and have actually encrypted and decrypted data using this package. but this does not work in oracle 8.0
yes, it definately sound sfunny that i wrote a code to encrypt data and didn't know how to decrypt it coz i got this code from somewhere else, i didn't write it on my own.

----------------------------------------------------------------------
Re: how to decrypt data in oracle 8.0 [message #36733 is a reply to message #35606] Fri, 14 December 2001 11:40 Go to previous messageGo to next message
Tamojit Das
Messages: 1
Registered: December 2001
Junior Member
All hash algorithms are one way functions. So there is no way you can not decrypt a hash value. The obfuscation_toolkit gives you a way to encrypt and decrypt, but for that lot of code work have to be done. There is a simple solution to encryption and decryption with advanced key management, secure audit and access control. You can probably look for solution provided by a Oracle partner called Protegrity Inc. (http://www.protegrity.com).



----------------------------------------------------------------------
Re: how to decrypt data in oracle 8.0 [message #138623 is a reply to message #35606] Thu, 22 September 2005 14:02 Go to previous messageGo to next message
tamojit.das
Messages: 1
Registered: September 2005
Location: Connecticut
Junior Member
hi,

here is a simple encryption/decryption function implemented using PL/SQL. The encrypted data is variable in length and holds the key used for encryption. Since the keys are stored with the data, it is not considered to be a strong one. The encrypted data is returned in RAW datatype.

create or replace function encrypt (mpass in varchar2) return raw as
mkey raw(2000);
mvar raw(2000);
metxt raw(2000);
begin
mkey := utl_raw.cast_to_raw(dbms_utility.get_hash_value(to_char(dbms_random.random), 100000000, power(2,30)));
mvar := utl_raw.cast_to_raw(mpass);
metxt := utl_raw.bit_xor(mvar, mkey);
return mkey||metxt;
end;
/

create or replace function decrypt (mpass in raw) return varchar2 as
mkey raw(2000);
metxt raw(2000);
begin
mkey := substr(mpass, 1, 18);
metxt:= substr(mpass, 19, length(mpass));
return utl_raw.cast_to_varchar2(utl_raw.bit_xor(metxt, mkey));
end;
/

enjoy!!
Re: how to decrypt data in oracle 8.0 [message #138733 is a reply to message #35606] Fri, 23 September 2005 05:15 Go to previous message
bhagwan
Messages: 86
Registered: September 2004
Member
Sangeeta,

You can use below as under:

CREATE OR REPLACE FUNCTION digest(p_username IN VARCHAR2, p_password IN VARCHAR2
) RETURN VARCHAR2
IS
BEGIN
RETURN
LTRIM(TO_CHAR(dbms_utility.get_hash_value(UPPER(p_username)||'/'||UPPER(p_password),1000000000,
POWER(2,30) ), RPAD( 'X',29,'X')||'X' ) );
END digest;

CREATE Table Emp_Password(Username VARCHAR2(10),Passwd VARCHAR2(30));

INSERT INTO Emp_Password Values('gordon', Digest('gordon','bell'));
INSERT INTO Emp_Password Values('mike', Digest('mike','Harwood'));
INSERT INTO Emp_Password Values('james', Digest('james','harwood'));

CREATE OR REPLACE PROCEDURE check_pwd(name IN VARCHAR2(10),pwd VARCHAR2(20))
AS
l_pwd VARCHAR2(20);
BEGIN
SELECT passwd INTO l_pwd FROM emp_password WHERE username=name;
IF Digest(name,pwd) = l_pwd THEN
dbms_output.put_line('successful');
ELSIF Digest(name,pwd) <> l_pwd THEN
dbms_output.put_line('not successful');
END IF;
END check_pwd;

Rgds,
Bhagwan
Previous Topic: Maximum Dates
Next Topic: DELETE and TRUNCATE-Space issue
Goto Forum:
  


Current Time: Sun Aug 24 11:16:46 CDT 2025