Encryptar y desencryptar en oracle

Solo disponible en BuenasTareas
  • Páginas : 3 (549 palabras )
  • Descarga(s) : 0
  • Publicado : 18 de noviembre de 2011
Leer documento completo
Vista previa del texto
Data Encryption - DBMS_OBFUSCATION_TOOLKIT
The DBMS_OBFUSCATION_TOOLKIT package provides a simple API for data encryption. Oracle8i only provides DES encryption whilst Oracle9i also includes DES3encryption. In this article I'll create a simple package containing functions to DES encrypt and decrypt test strings:
• Create the Package
• Create the Package Body
• Test It
• Encrypt TableData
Create the Package
First we create the package header containing the two conversion functions.
CREATE OR REPLACE PACKAGE toolkit AS

FUNCTION encrypt (p_text IN VARCHAR2) RETURN RAW;FUNCTION decrypt (p_raw IN RAW) RETURN VARCHAR2;

END toolkit;
/
Create the Package Body
All VARCHAR2 inputs are padded to multiples of 8 charaters, with the encryption key also being amultiple of 8 charaters. The encryption key and padding characters can be altered to suit.
CREATE OR REPLACE PACKAGE BODY toolkit AS

g_key RAW(32767) := UTL_RAW.cast_to_raw('12345678');g_pad_chr VARCHAR2(1) := '~';

PROCEDURE padstring (p_text IN OUT VARCHAR2);

-- --------------------------------------------------
FUNCTION encrypt (p_text IN VARCHAR2) RETURN RAW IS-- --------------------------------------------------
l_text VARCHAR2(32767) := p_text;
l_encrypted RAW(32767);
BEGIN
padstring(l_text);DBMS_OBFUSCATION_TOOLKIT.desencrypt(input => UTL_RAW.cast_to_raw(l_text),
key => g_key,
encrypted_data => l_encrypted);
RETURNl_encrypted;
END;
-- --------------------------------------------------

-- --------------------------------------------------
FUNCTION decrypt (p_raw IN RAW) RETURN VARCHAR2 IS
----------------------------------------------------
l_decrypted VARCHAR2(32767);
BEGIN
DBMS_OBFUSCATION_TOOLKIT.desdecrypt(input => p_raw,
key...
tracking img