Tags

, , ,


——————————————————–

—  DDL for Function DES_DECRYPT

——————————————————–

CREATE OR REPLACE FUNCTION “DES_DECRYPT” (

input_string VARCHAR2,

key_string VARCHAR2

) RETURN VARCHAR2

IS

v_return VARCHAR2(2048);

v_key_string VARCHAR2(56);

BEGIN

IF LENGTH(key_string) > 56 THEN

RAISE_APPLICATION_ERROR(-20100, ‘des_decrypt – key longer than 56 bytes’);

END IF;

IF MOD(LENGTH(input_string),8) != 0 THEN

RAISE_APPLICATION_ERROR(-20101, ‘des_decrypt – input length is not mod 8’);

END IF;

v_key_string := RPAD(key_string,56,’X’);

dbms_obfuscation_toolkit.desdecrypt(

input_string => input_string,

key_string => v_key_string,

decrypted_string => v_return

);

RETURN RTRIM(v_return);

END;

/

——————————————————–

—  DDL for Function DES_ENCRYPT

——————————————————–

CREATE OR REPLACE FUNCTION “DES_ENCRYPT” (

input_string VARCHAR2,

key_string VARCHAR2

) RETURN VARCHAR2

IS

v_return VARCHAR2(2048);

v_input_string VARCHAR2(2048);

v_key_string VARCHAR2(56);

BEGIN

IF LENGTH(key_string) > 56 THEN

RAISE_APPLICATION_ERROR(-20100, ‘des_decrypt – key longer than 56 bytes’);

END IF;

v_key_string := RPAD(key_string,56,’X’);

v_input_string := RPAD(input_string, LENGTH(input_string) + ( 8 – MOD(LENGTH(input_string),8)) ) ;

dbms_obfuscation_toolkit.desencrypt(

input_string => v_input_string,

key_string => v_key_string,

encrypted_string => v_return

);

RETURN v_return;

END;

/

Usage:

After running both the functions, one can use the same as in the example below

Encrypt:

update table_name set column_name=DES_ENCRYPT(column_name,’Commonkey’)

Decrypt:

update table_name set column_name=DES_DECRYPT(column_name,’Commonkey’)


Advertisements