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