How to use DBMS_CRYPTO.encrypt function in oracle

ITQuest picture ITQuest · Sep 9, 2015 · Viewed 33.7k times · Source

I want to encrypt password column in the database and I am trying to use encrypt function present inside DBMS_CRYPTO package (have given execute access from sys account to the current user) but I am getting the following error. Please give me some examples of how to use this function:

select DBMS_CRYPTO.encrypt('12345', dbms_crypto.DES_CBC_PKCS5, 'A1') from dual;

Error:

ORA-06553: PLS-221: 'DES_CBC_PKCS5' is not a procedure or is undefined 06553. 00000 - "PLS-%s: %s"

Answer

Marmite Bomber picture Marmite Bomber · Sep 9, 2015

The constant dbms_crypto.DES_CBC_PKCS5 is referenceble on PL/SQL only - not from SQL.

You must replace it with literal value in the SELECT statement.

To get the value use PL/SQL block

 begin
   dbms_output.put_line(dbms_crypto.DES_CBC_PKCS5);
 end;
 /

.

 4353

You must also use a longer key

 select DBMS_CRYPTO.encrypt(UTL_RAW.CAST_TO_RAW ('ABCDEFGH12345'), 4353 /* = dbms_crypto.DES_CBC_PKCS5 */, 'A1A2A3A4A5A6CAFE') from dual;

 9320CBCBD25E8721BD04990A0EAEAF00