How to encrypt/decrypt strings with the dbms_obfuscation_toolkit / dbms_crypto packages
Oracle 9i dbms_obfuscation_toolkit package
|
CREATE OR REPLACE PACKAGE Cryptit AS CREATE OR REPLACE PACKAGE BODY Cryptit AS -- Encrypt the string -- l INTEGER := LENGTH(str); BEGIN dbms_obfuscation_toolkit.DESEncrypt( -- Decrypt the string -- |
|
SQL*Plus: Release 9.0.1.3.0 - Production on Je Oct 13 10:28:55 2005 (c) Copyright 2001 Oracle Corporation. All rights reserved.
SQL> set serveroutput on Procédure PL/SQL terminée avec succès. SQL> |
SQL> set serveroutput on PL/SQL procedure successfully completed. SQL>
Oracle 10g dbms_crypto package
SQL>
SQL> DECLARE
2 LC$Source VARCHAR2(19) := 'Music is the best!';
3 LR$Source RAW(128) := utl_raw.cast_to_raw(LC$Source);
4 LR$Key RAW(128) := utl_raw.cast_to_raw('FrankZappa');
5 LR$Crypted RAW(2048);
6 LR$Decrypted RAW(2048);
7
8 BEGIN
9
10 dbms_output.put_line('Source string : ' || LC$Source);
11
12 LR$Crypted := dbms_crypto.encrypt(LR$Source,
13 dbms_crypto.des_cbc_pkcs5, LR$Key);
14
15 dbms_output.put_line('Encrypted raw : ' ||
16 RAWTOHEX(utl_raw.cast_to_raw(LR$Crypted)));
17
18 LR$Decrypted := dbms_crypto.decrypt(src => LR$Crypted,
19 typ => dbms_crypto.des_cbc_pkcs5, key => LR$Key);
20
21 dbms_output.put_line('Decrypted string : ' ||
22 utl_raw.cast_to_varchar2(LR$Decrypted));
23 END;
24 /
Source string : Music is the best!
Encrypted raw :
33454635363638343931453734313342373337454141313133453637323639373934373433463442
4533464246333831
Decrypted string : Music is the best!
Francois
| Juillet 2009 | ||||||||||
| L | M | M | J | V | S | D | ||||
| 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 | ||||||
|
||||||||||