Aşağıdaki örnekte BLOB datasını nasıl encrypt ve decrypt yapıldıgını gosteriyorum.

* İlk önce yeni bir tablo create edelim(içinde BLOB kolon olan)
* RAW deger insert edelim
* Raw datayı Encrypt edelim.
* Encrypt ettigimiz datayı Decrypt edelim.


create table table_lob (id number, loc blob);

-- 3 tane bos lobs for src/enc/dec insert edelim

insert into table_lob values (1, EMPTY_BLOB());
insert into table_lob values (2, EMPTY_BLOB());
insert into table_lob values (3, EMPTY_BLOB());


declare
srcdata RAW(1000);
srcblob BLOB;
encrypblob BLOB;
encrypraw RAW(1000);
encrawlen BINARY_INTEGER;
decrypblob BLOB;
decrypraw RAW(1000);
decrawlen BINARY_INTEGER;
leng INTEGER;

begin

-- 16 bytes raw datayı girelim
srcdata := hextoraw('6D6D6D6D6D6D6D6D6D6D6D6D6D6D6D6D');

dbms_output.put_line('---');
dbms_output.put_line('girilen data ' || srcdata);
dbms_output.put_line('---');

-- Bos lob locator for src/enc/dec select edelim

select loc into srcblob from table_lob where id = 1;
select loc into encrypblob from table_lob where id = 2;
select loc into decrypblob from table_lob where id = 3;

dbms_output.put_line('Bos create ettik LOBS');
dbms_output.put_line('---');

leng := DBMS_LOB.GETLENGTH(srcblob);
IF leng IS NULL THEN
dbms_output.put_line('Kaynak BLOB uzunlugu NULL ');
ELSE
dbms_output.put_line('Kaynak BLOB Uzunlugu ' || leng);
END IF;

leng := DBMS_LOB.GETLENGTH(encrypblob);
IF leng IS NULL THEN
dbms_output.put_line('Encrypt BLOB uzunlugu NULL ');
ELSE
dbms_output.put_line('Encrypt BLOB uzunlugu ' || leng);
END IF;

leng := DBMS_LOB.GETLENGTH(decrypblob);
IF leng IS NULL THEN
dbms_output.put_line('Decrypt BLOB uzunlugu NULL ');
ELSE
dbms_output.put_line('Decrypt BLOB uzunlugu ' || leng);
END IF;

-- source raw datasını blob yazalım

DBMS_LOB.OPEN (srcblob, DBMS_LOB.lob_readwrite);
DBMS_LOB.WRITEAPPEND (srcblob, 16, srcdata);
DBMS_LOB.CLOSE (srcblob);

dbms_output.put_line('Kaynak raw data yazıldı kaynak blob');
dbms_output.put_line('---');

leng := DBMS_LOB.GETLENGTH(srcblob);
IF leng IS NULL THEN
dbms_output.put_line('kaynak BLOB uzunlugu NULL ');
ELSE
dbms_output.put_line('kaynak BLOB uzunlugu ' || leng);
END IF;

DBMS_CRYPTO.Encrypt(encrypblob,
srcblob,
DBMS_CRYPTO.AES_CBC_PKCS5,
hextoraw ('000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F'),
hextoraw('00000000000000000000000000000000'));


dbms_output.put_line('Encryption yapıldı');
dbms_output.put_line('---');

leng := DBMS_LOB.GETLENGTH(encrypblob);
IF leng IS NULL THEN
dbms_output.put_line('Encrypt BLOB uzunlugu NULL');
ELSE
dbms_output.put_line('Encrypt BLOB uzunlugu ' || leng);
END IF;

-- encrypblob to a raw okuyalım
encrawlen := 999;

DBMS_LOB.OPEN (encrypblob, DBMS_LOB.lob_readwrite);
DBMS_LOB.READ (encrypblob, encrawlen, 1, encrypraw);
DBMS_LOB.CLOSE (encrypblob);

dbms_output.put_line('encrypt blob raw okundu');
dbms_output.put_line('---');

dbms_output.put_line('Encrypted data (256 bit key) ' || encrypraw);
dbms_output.put_line('---');


DBMS_CRYPTO.Decrypt(decrypblob,
encrypblob,
DBMS_CRYPTO.AES_CBC_PKCS5,
hextoraw
('000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F'),
hextoraw('00000000000000000000000000000000'));

leng := DBMS_LOB.GETLENGTH(decrypblob);
IF leng IS NULL THEN
dbms_output.put_line('Decrypt BLOB Uzunlugu NULL');
ELSE
dbms_output.put_line('Decrypt BLOB Uzunlugu ' || leng);
END IF;

-- decrypblob raw okuyalım
decrawlen := 999;

DBMS_LOB.OPEN (decrypblob, DBMS_LOB.lob_readwrite);
DBMS_LOB.READ (decrypblob, decrawlen, 1, decrypraw);
DBMS_LOB.CLOSE (decrypblob);

dbms_output.put_line('Decrypted data (256 bit key) ' || decrypraw);
dbms_output.put_line('---');

DBMS_LOB.OPEN (srcblob, DBMS_LOB.lob_readwrite);
DBMS_LOB.TRIM (srcblob, 0);
DBMS_LOB.CLOSE (srcblob);

DBMS_LOB.OPEN (encrypblob, DBMS_LOB.lob_readwrite);
DBMS_LOB.TRIM (encrypblob, 0);
DBMS_LOB.CLOSE (encrypblob);

DBMS_LOB.OPEN (decrypblob, DBMS_LOB.lob_readwrite);
DBMS_LOB.TRIM (decrypblob, 0);
DBMS_LOB.CLOSE (decrypblob);

end;
/