Ora-01405 Thrown when Encrypting Blob Using dbms_crypto.encrypt Package (Doc ID 1288044.1)

Last updated on JULY 05, 2017

Applies to:

PL/SQL - Version: 10.2.0.5 to 11.2.0.2 - Release: 10.2 to 11.2
Information in this document applies to any platform.

Symptoms

Executing dbms_crypto.encrypt procedure fails with ORA-01405.

Create sample table with Blob column

create table btest_enc(id number, vblob blob);
insert into btest_enc values (100, utl_raw.CAST_TO_RAW('This is a test'));
commit;

Sample dbms_crypto.encrypt code that FAILS
set serveroutput on
declare
v_algorithm number := dbms_crypto.ENCRYPT_AES128 + dbms_crypto.CHAIN_CBC + dbms_crypto.PAD_PKCS5;
v_enc_blob blob;
p_src_blob blob;
v_key RAW(256);
leng number;
v_message varchar2(4000);
begin
dbms_output.put_line('Hi there');
v_key := dbms_crypto.randombytes(16);
select vblob into p_src_blob from btest_enc where id = 100;

leng := DBMS_LOB.GETLENGTH(p_src_blob);
IF leng IS NULL THEN
dbms_output.put_line('Source BLOB Len NULL ');
ELSE
dbms_output.put_line('Source BLOB Len ' || leng);
END IF;

dbms_crypto.encrypt(dst => v_enc_blob,
src => p_src_blob,
key => v_key,
typ => v_algorithm);

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

dbms_output.put_line('Encryption Done');

exception
when others then
v_message := 'Error_Stack...' || Chr(10) || DBMS_UTILITY.FORMAT_ERROR_STACK();
v_message := v_message || 'Error_Backtrace...' || Chr(10) || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE();
dbms_output.put_line(v_message);

END;
/

Output
Hi there
Source BLOB Len 14
Error_Stack...
ORA-01405: fetched column value is NULL
Error_Backtrace...
ORA-06512: at "SYS.DBMS_CRYPTO_FFI", line 26
ORA-06512: at "SYS.DBMS_CRYPTO", line 20
ORA-06512: at line 20

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms