Password Encrypt Query in Oracle

CREATE OR REPLACE PACKAGE ENCRY_PASS AS
FUNCTION encrypt( Str VARCHAR2 ) RETURN RAW;
FUNCTION decrypt( xCrypt VARCHAR2 ) RETURN VARCHAR2;
END ENCRY_PASS;
/

CREATE OR REPLACE PACKAGE BODY ENCRY_PASS AS
crypt_raw RAW(2000);
crypt_str VARCHAR(2000);

-- Encrypt the string --
FUNCTION encrypt( Str VARCHAR2 ) RETURN RAW AS

l INTEGER := LENGTH(str);
i INTEGER;
padblock RAW(2000);
Cle RAW(8) := UTL_RAW.CAST_TO_RAW('frankzap');

BEGIN
i := 8-MOD(l,8);
padblock := utl_raw.cast_to_raw(str||RPAD(CHR(i),i,CHR(i)));

dbms_obfuscation_toolkit.DESEncrypt(
input => padblock,
KEY => Cle,
encrypted_data => crypt_raw );
RETURN crypt_raw ;
END;

-- Decrypt the string --
FUNCTION decrypt( xCrypt VARCHAR2 ) RETURN VARCHAR2 AS
l NUMBER;
Cle RAW(8) := UTL_RAW.CAST_TO_RAW('frankzap');
crypt_raw RAW(2000) := utl_raw.cast_to_raw(utl_raw.cast_to_varchar2(xCrypt)) ;
BEGIN
dbms_obfuscation_toolkit.DESDecrypt(
input => xCrypt,
KEY => Cle,
decrypted_data => crypt_raw );
crypt_str := utl_raw.cast_to_varchar2(crypt_raw);
l := LENGTH(crypt_str);
crypt_str := RPAD(crypt_str,l-ASCII(SUBSTR(crypt_str,l)));
RETURN crypt_str;
END;
END ENCRY_PASS;
/

0 Response to "Password Encrypt Query in Oracle"

Post a Comment

Powered by Blogger