API: DBMS_CRYPTO: encrypt and decrypt information
To Encrypt or decrypt, we will need a key. This key will be stored in a table which can be accessed only by the authorized personnel.
In the below examples, the key has been hardcoded.
In the below examples, the key has been hardcoded.
dbms_crypto example to encrypt information
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
Declare
l_key varchar2(2000) := '1234567890123456';
l_mod number := dbms_crypto.ENCRYPT_AES128
+ dbms_crypto.CHAIN_CBC
+ dbms_crypto.PAD_PKCS5;
l_enc raw (2000);
begin
l_enc := dbms_crypto.encrypt
(
UTL_I18N.STRING_TO_RAW (p_in_val, 'AL32UTF8'),
l_mod,
UTL_I18N.STRING_TO_RAW (l_key, 'AL32UTF8')
);
end;
|
dbms_crypto example to decrypt information
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
Declare
l_key varchar2(2000) := '1234567890123456';
lv_in_val raw (2000) := hextoraw(p_in_val);
l_mod number := dbms_crypto.ENCRYPT_AES128
+ dbms_crypto.CHAIN_CBC
+ dbms_crypto.PAD_PKCS5;
l_dec raw (2000);
begin
<code> l_dec := dbms_crypto.decrypt
(
lv_in_val,
l_mod,
UTL_I18N.STRING_TO_RAW (l_key, 'AL32UTF8')
);
dbms_output.put_line
('Decrypted='||utl_i18n.raw_to_char(l_dec));
end;
|
No comments:
Post a Comment