Skip to content

Commit 8803137

Browse files
committed
code upload
adding source code and updated readme text
1 parent 0c971b6 commit 8803137

File tree

6 files changed

+383
-0
lines changed

6 files changed

+383
-0
lines changed

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,68 @@ Oracle-Application-Level-Encryption-Decryption
22
==============================================
33

44
Oracle based application level Encryption and Decryption utilities for 10g and 11g(AES enabled)
5+
6+
7+
8+
/*----------------------------------------------------------------------------------------
9+
-- FILE NAME : ReadMe.txt
10+
-- Generated By : Exilant Technologies Private Limited
11+
-- Description : Instructions for installing the Error Logging & Encryption utility
12+
-- Date : May 18, 2012
13+
-- Author : Ex!lant Dev Team
14+
-- Modification History:
15+
------------------------------------------------------------------------------------------
16+
-- When Who What
17+
------------------------------------------------------------------------------------------
18+
-- 18/05/2012 Ex! Dev Team Initial Version
19+
----------------------------------------------------------------------------------------*/
20+
21+
1. Please place all the source code files provided in one single location ( preferably a single directory )
22+
a. error_log.ddl
23+
b. ex_crypto_pkg.ddl
24+
c. ex_crypto_pkg_body.ddl
25+
d. run_before_install.sql
26+
27+
2. Please run the file : run_before_install.sql to verify that there is no conflict with an existing object in your database.
28+
If there are any objects in the list generated by script then you may wish to manually inspect the DB object(s) before executing
29+
the next steps to avoid any data / object loss.
30+
31+
3. Compile the script : error_log.ddl
32+
The script expects tablespace named 'ext_data_ts' to be present and accessible.
33+
Please replace the same with appropriate tablespace name OR remove the tablespace clause as applicable.
34+
35+
e.g : from unix prompt - after logging into oracle , fire the command
36+
@error_log.ddl
37+
38+
4. Compile the script : ex_crypto_pkg.ddl
39+
40+
5. Execute wrap utility for hiding the :
41+
E.g : In a unix box , which has oracle connectivity defined (i.e. $ORACLE, $TNS_HOME etc. are defined) execute this command
42+
wrap iname=ex_crypto_pkg_body.ddl
43+
44+
This will generate a file named : ex_crypto_pkg_body.plb
45+
46+
Compile this file as usual :
47+
E.g : from unix prompt - after logging into oracle , fire the command
48+
@ ex_crypto_pkg_body.plb
49+
50+
6. Verify that the encryption package is working properly by using the sample below:
51+
52+
SELECT ex_crypto.f_decrypt(ex_crypto.f_encrypt('Exilant Technologies Pvt. Ltd.')) FROM DUAL;
53+
54+
--This command will validate both encryption and decryption functions. For detailed function list , please refer to Usage Instructions.
55+
56+
7. Delete the source file(s) :
57+
a. ex_crypto_pkg.ddl
58+
b. ex_crypto_pkg_body.ddl
59+
c. ex_crypto_pkg_body.plb
60+
61+
8. Uninstall process:
62+
Please ensure that the error log table and logging procedure don't have any other dependency or are getting used anywhere.
63+
Also, it is suggested to take a backup of error log table , in case the error logging module is to be used separately.
64+
65+
Compile the script :
66+
uninstall_encryption.sql
67+
68+
This will systematically remove all components installed as part of the crypto module.
69+

error_log.ddl

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*----------------------------------------------------------------------------------------
2+
-- FILE NAME : error_log.ddl
3+
-- Generated By : Ex!lant Technologies Pvt Ltd.
4+
-- Description : Generic Error Logging utility
5+
-- Date : May 18, 2012
6+
-- Author : Ex!lant Development Team
7+
-- Modification History:
8+
------------------------------------------------------------------------------------------
9+
-- When Who What
10+
------------------------------------------------------------------------------------------
11+
-- 18/05/2012 Ex! Dev Team Initial Version
12+
----------------------------------------------------------------------------------------*/
13+
SET HEAD ON PAGES 3000 LINES 300 FEEDBACK ON
14+
15+
DROP TABLE error_log;
16+
DROP PUBLIC SYNONYM error_log;
17+
DROP SEQUENCE error_seq;
18+
DROP PUBLIC SYNONYM error_seq;
19+
DROP PROCEDURE p_log_error;
20+
DROP PUBLIC SYNONYM p_log_error;
21+
22+
CREATE SEQUENCE error_seq
23+
START WITH 1 INCREMENT BY 1 CACHE 100 NOMAXVALUE;
24+
25+
CREATE OR REPLACE PUBLIC SYNONYM error_seq FOR error_seq;
26+
27+
CREATE TABLE error_log
28+
( error_id NUMBER NOT NULL,
29+
error_cd INTEGER NOT NULL,
30+
error_msg VARCHAR2 (4000) NOT NULL,
31+
program_err_msg VARCHAR2 (1000) NOT NULL,
32+
backtrace CLOB,
33+
callstack CLOB,
34+
cre_dt DATE DEFAULT SYSDATE NOT NULL,
35+
program_nm VARCHAR2 (30) NOT NULL,
36+
cre_user VARCHAR2 (30) DEFAULT USER NOT NULL,
37+
CONSTRAINT pk_error_log PRIMARY KEY ( cre_dt,program_nm,error_id ) USING INDEX TABLESPACE ext_data_ts LOCAL
38+
)
39+
PARTITION BY RANGE(cre_dt)
40+
INTERVAL(NUMTOYMINTERVAL(1, 'MONTH'))
41+
( PARTITION p0 VALUES LESS THAN (TO_DATE('01-01-2012','DD-MM-YYYY')) COMPRESS)
42+
TABLESPACE ext_data_ts;
43+
44+
45+
CREATE OR REPLACE PUBLIC SYNONYM error_log FOR error_log;
46+
47+
CREATE OR REPLACE PROCEDURE p_log_error ( in_v_err_msg IN error_log.program_err_msg%TYPE,
48+
in_v_program_nm IN error_log.program_nm%TYPE )
49+
AUTHID CURRENT_USER AS
50+
l_code PLS_INTEGER := SQLCODE;
51+
l_mesg VARCHAR2(32767) := SQLERRM;
52+
PRAGMA AUTONOMOUS_TRANSACTION;
53+
BEGIN
54+
INSERT INTO error_log ( error_id,
55+
error_cd,
56+
error_msg,
57+
program_err_msg,
58+
backtrace,
59+
callstack,
60+
program_nm
61+
)
62+
VALUES ( error_seq.NEXTVAL,
63+
l_code,
64+
l_mesg,
65+
TRIM(in_v_err_msg),
66+
SYS.DBMS_UTILITY.format_error_backtrace,
67+
SYS.DBMS_UTILITY.format_call_stack,
68+
in_v_program_nm);
69+
COMMIT;
70+
END;
71+
/
72+
73+
CREATE OR REPLACE PUBLIC SYNONYM p_log_error FOR p_log_error;
74+
75+
GRANT EXECUTE ON p_log_error TO PUBLIC;
76+
GRANT SELECT ON error_seq TO PUBLIC;
77+
GRANT INSERT ON error_log TO PUBLIC;
78+

ex_crypto_pkg.sql

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*----------------------------------------------------------------------------------------
2+
-- FILE NAME : ex_crypto_pkg.sql
3+
-- Generated By : Ex!lant Technologies Pvt Ltd.
4+
-- Description : Package declaration for ex_crypto Oracle based 3DES encryption and
5+
-- decryption utilities
6+
-- Date : May 18, 2012
7+
-- Author : Ex!lant Development Team
8+
-- Modification History:
9+
------------------------------------------------------------------------------------------
10+
-- When Who What
11+
------------------------------------------------------------------------------------------
12+
-- 18/05/2012 Ex! Dev Team Initial Version
13+
----------------------------------------------------------------------------------------*/
14+
15+
CREATE OR REPLACE PACKAGE ex_crypto
16+
AUTHID CURRENT_USER
17+
AS
18+
FUNCTION f_encrypt( in_encrypt IN VARCHAR2, in_n_3des_flag IN PLS_INTEGER DEFAULT 0) RETURN VARCHAR2 DETERMINISTIC;
19+
FUNCTION f_encrypt( in_encrypt IN NUMBER, in_n_3des_flag IN PLS_INTEGER DEFAULT 0) RETURN VARCHAR2 DETERMINISTIC;
20+
FUNCTION f_encrypt_raw( in_encrypt IN RAW, in_n_3des_flag IN PLS_INTEGER DEFAULT 0) RETURN RAW DETERMINISTIC;
21+
FUNCTION f_decrypt( in_decrypt IN VARCHAR2, in_n_3des_flag IN PLS_INTEGER DEFAULT 0) RETURN VARCHAR2 DETERMINISTIC;
22+
FUNCTION f_decrypt_raw( in_decrypt IN RAW, in_n_3des_flag IN PLS_INTEGER DEFAULT 0) RETURN RAW DETERMINISTIC;
23+
24+
gv_pgm_nm error_log.program_err_msg%TYPE := 'f_encrypt';
25+
gv_err_msg error_log.program_err_msg%TYPE;
26+
gv_o_encrypted_string VARCHAR2(32767);
27+
gv_o_decrypted_string VARCHAR2(32767);
28+
gv_raw_encryption_key RAW(32767);
29+
gv_string VARCHAR2(32767);
30+
gv_raw RAW(32767);
31+
gv_encryption_key VARCHAR2(56);
32+
gv_o_raw_encrypted_string RAW(32767);
33+
ge_null_input EXCEPTION;
34+
ge_invalid_key EXCEPTION;
35+
36+
END ex_crypto;
37+
/
38+
SHO ERR
39+
40+
CREATE OR REPLACE PUBLIC SYNONYM ex_crypto FOR ex_crypto;
41+
42+
GRANT EXECUTE ON ex_crypto TO PUBLIC;

ex_crypto_pkg_body.sql

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*----------------------------------------------------------------------------------------
2+
-- FILE NAME : ex_crypto_pkg_body.sql
3+
-- Generated By : Ex!lant Technologies Pvt Ltd.
4+
-- Description : Package body for ex_crypto Oracle based 3DES encryption and
5+
-- decryption utilities
6+
-- Date : May 18, 2012
7+
-- Author : Ex!lant Development Team
8+
-- Modification History:
9+
------------------------------------------------------------------------------------------
10+
-- When Who What
11+
------------------------------------------------------------------------------------------
12+
-- 18/05/2012 Ex! Dev Team Initial Version
13+
----------------------------------------------------------------------------------------*/
14+
CREATE OR REPLACE PACKAGE BODY ex_crypto
15+
AS
16+
PROCEDURE p_round8( in_v_string IN OUT VARCHAR2)
17+
IS
18+
ln_str_len PLS_INTEGER;
19+
BEGIN
20+
SELECT VSIZE(TRIM(in_v_string)) INTO ln_str_len FROM DUAL;
21+
CASE
22+
WHEN MOD(ln_str_len,8)= 0 THEN in_v_string := TRIM(in_v_string);
23+
ELSE in_v_string := LPAD(TRIM(in_v_string), 8 - MOD(ln_str_len,8) + LENGTH(TRIM(in_v_string)));
24+
END CASE;
25+
26+
EXCEPTION
27+
WHEN OTHERS THEN
28+
gv_pgm_nm := 'p_round8';
29+
gv_err_msg := 'Error occurred while processing input string :'||in_v_string;
30+
p_log_error(gv_err_msg, gv_pgm_nm);
31+
in_v_string := NULL;
32+
END p_round8 ;
33+
34+
FUNCTION f_string_encrypt( in_encrypt IN VARCHAR2, in_n_3des_flag IN PLS_INTEGER DEFAULT 0)
35+
RETURN VARCHAR2
36+
IS
37+
BEGIN
38+
gv_pgm_nm := 'f_string_encrypt';
39+
gv_encryption_key := 'Ex!l@n8Te3hn0l0giesPr1v@8L1m1teD';
40+
gv_encryption_key := gv_encryption_key||'EnCryPt10NAlg0Rdm7860666';
41+
gv_string := TRIM(in_encrypt);
42+
43+
IF gv_string IS NULL THEN
44+
RAISE ge_null_input;
45+
ELSIF in_n_3des_flag > 1 THEN
46+
RAISE ge_invalid_key;
47+
ELSE
48+
p_round8(gv_string);
49+
DBMS_OBFUSCATION_TOOLKIT.DES3Encrypt(input_string => gv_string,
50+
key_string => gv_encryption_key,
51+
encrypted_string => gv_o_encrypted_string,
52+
which => in_n_3des_flag);
53+
END IF;
54+
RETURN gv_o_encrypted_string;
55+
EXCEPTION
56+
WHEN ge_null_input THEN
57+
gv_err_msg := 'NULL Input string provided';
58+
p_log_error(gv_err_msg, gv_pgm_nm);
59+
RETURN NULL;
60+
WHEN ge_invalid_key THEN
61+
gv_err_msg := 'Invalid WHICH key provided for input string :'||in_encrypt||' AND 3DES '||in_n_3des_flag;
62+
p_log_error(gv_err_msg, gv_pgm_nm);
63+
RETURN NULL;
64+
WHEN OTHERS THEN
65+
gv_err_msg := 'Error occurred while processing input string :'||in_encrypt||' AND 3DES '||in_n_3des_flag;
66+
p_log_error(gv_err_msg, gv_pgm_nm);
67+
RETURN NULL;
68+
END f_string_encrypt;
69+
70+
FUNCTION f_encrypt(in_encrypt IN NUMBER, in_n_3des_flag IN PLS_INTEGER DEFAULT 0)
71+
RETURN VARCHAR2
72+
IS
73+
BEGIN
74+
RETURN f_string_encrypt(TO_CHAR(in_encrypt),in_n_3des_flag);
75+
EXCEPTION
76+
WHEN OTHERS THEN
77+
gv_pgm_nm := 'f_encrypt';
78+
gv_err_msg := 'Error occurred while processing input NUMBER :'||in_encrypt||' AND 3DES '||in_n_3des_flag;
79+
p_log_error(gv_err_msg, gv_pgm_nm);
80+
RETURN NULL;
81+
END f_encrypt;
82+
83+
FUNCTION f_encrypt( in_encrypt IN VARCHAR2, in_n_3des_flag IN PLS_INTEGER DEFAULT 0)
84+
RETURN VARCHAR2
85+
IS
86+
BEGIN
87+
RETURN f_string_encrypt(in_encrypt,in_n_3des_flag);
88+
END f_encrypt;
89+
90+
FUNCTION f_encrypt_raw(in_encrypt IN RAW, in_n_3des_flag IN PLS_INTEGER DEFAULT 0)
91+
RETURN RAW
92+
IS
93+
BEGIN
94+
RETURN UTL_RAW.CAST_TO_RAW(f_string_encrypt(UTL_RAW.CAST_TO_VARCHAR2(TRIM(in_encrypt)),in_n_3des_flag));
95+
EXCEPTION
96+
WHEN OTHERS THEN
97+
gv_pgm_nm := 'f_encrypt_raw';
98+
gv_err_msg := 'Error occurred while processing input RAW string :'||in_encrypt||' AND 3DES '||in_n_3des_flag;
99+
p_log_error(gv_err_msg, gv_pgm_nm);
100+
RETURN NULL;
101+
END f_encrypt_raw;
102+
103+
FUNCTION f_string_decrypt ( in_decrypt IN VARCHAR2, in_n_3des_flag IN PLS_INTEGER DEFAULT 0)
104+
RETURN VARCHAR2
105+
IS
106+
BEGIN
107+
gv_pgm_nm := 'f_string_decrypt';
108+
gv_encryption_key := 'Ex!l@n8Te3hn0l0giesPr1v@8L1m1teD';
109+
gv_encryption_key := gv_encryption_key||'EnCryPt10NAlg0Rdm7860666';
110+
111+
IF TRIM(in_decrypt) IS NULL THEN
112+
RAISE ge_null_input;
113+
ELSIF in_n_3des_flag > 1 THEN
114+
RAISE ge_invalid_key;
115+
ELSE
116+
DBMS_OBFUSCATION_TOOLKIT.DES3Decrypt(input_string => in_decrypt,
117+
key_string => gv_encryption_key,
118+
decrypted_string => gv_o_decrypted_string,
119+
which => in_n_3des_flag);
120+
END IF;
121+
RETURN TRIM(gv_o_decrypted_string);
122+
EXCEPTION
123+
WHEN ge_null_input THEN
124+
gv_err_msg := 'NULL Input Decryption string provided';
125+
p_log_error(gv_err_msg, gv_pgm_nm);
126+
RETURN NULL;
127+
WHEN ge_invalid_key THEN
128+
gv_err_msg := 'Invalid WHICH key provided for input string :'||in_decrypt||' AND 3DES '||in_n_3des_flag;
129+
p_log_error(gv_err_msg, gv_pgm_nm);
130+
RETURN NULL;
131+
WHEN OTHERS THEN
132+
gv_err_msg := 'Error occurred while processing input string :'||in_decrypt||' AND 3DES '||in_n_3des_flag;
133+
p_log_error(gv_err_msg, gv_pgm_nm);
134+
RETURN NULL;
135+
END f_string_decrypt;
136+
137+
FUNCTION f_decrypt( in_decrypt IN VARCHAR2, in_n_3des_flag IN PLS_INTEGER DEFAULT 0)
138+
RETURN VARCHAR2
139+
IS
140+
BEGIN
141+
RETURN f_string_decrypt (in_decrypt, in_n_3des_flag);
142+
EXCEPTION
143+
WHEN OTHERS THEN
144+
gv_pgm_nm := 'f_decrypt';
145+
gv_err_msg := 'Error occurred while processing input STRING :'||in_decrypt||' AND 3DES '||in_n_3des_flag;
146+
p_log_error(gv_err_msg, gv_pgm_nm);
147+
RETURN NULL;
148+
END f_decrypt;
149+
150+
FUNCTION f_decrypt_raw ( in_decrypt IN RAW, in_n_3des_flag IN PLS_INTEGER DEFAULT 0)
151+
RETURN RAW
152+
IS
153+
BEGIN
154+
RETURN UTL_RAW.CAST_TO_RAW(f_string_decrypt(UTL_RAW.CAST_TO_VARCHAR2(in_decrypt),in_n_3des_flag));
155+
EXCEPTION
156+
WHEN OTHERS THEN
157+
gv_pgm_nm := 'f_decrypt_raw';
158+
gv_err_msg := 'Error occurred while processing input RAW string :'||in_decrypt||' AND 3DES '||in_n_3des_flag;
159+
p_log_error(gv_err_msg, gv_pgm_nm);
160+
RETURN NULL;
161+
END f_decrypt_raw;
162+
163+
END ex_crypto;
164+
/
165+

run_before_install.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SET HEAD ON PAGES 3000 LINES 300 FEEDBACK ON
2+
3+
SELECT owner,object_name, object_type, created
4+
FROM all_objects
5+
WHERE object_name IN ('ERROR_LOG', 'ERROR_SEQ', 'P_LOG_ERROR','EX_CRYPTO','ENCRYPTION_EXAMPLE' )
6+
AND object_type IN ('SEQUENCE','SYNONYM','PACKAGE','PACKAGE BODY','PROCEDURE','TABLE')
7+
ORDER BY owner,object_type,object_name;

uninstall_encryption.sql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*----------------------------------------------------------------------------------------
2+
-- FILE NAME : uninstall_encryption.sql
3+
-- Generated By : Ex!lant Technologies Pvt Ltd.
4+
-- Description : Generic Error Logging utility
5+
-- Date : May 18, 2012
6+
-- Author : Ex!lant Development Team
7+
-- Modification History:
8+
------------------------------------------------------------------------------------------
9+
-- When Who What
10+
------------------------------------------------------------------------------------------
11+
-- 18/05/2012 Ex! Dev Team Initial Version
12+
----------------------------------------------------------------------------------------*/
13+
14+
--Please don't forget to take backup of data if any , including error_log table.
15+
16+
SET HEAD ON PAGES 300 LINES 3000 FEEDBACK ON
17+
18+
DROP PUBLIC SYNONYM ex_crypto;
19+
DROP PACKAGE ex_crypto;
20+
DROP PUBLIC SYNONYM error_log;
21+
DROP TABLE error_log;
22+
DROP PUBLIC SYNONYM error_seq;
23+
DROP SEQUENCE error_seq;
24+
DROP PUBLIC SYNONYM p_log_error;
25+
DROP PROCEDURE p_log_error;
26+
DROP TABLE encryption_example;

0 commit comments

Comments
 (0)