Sometimes it is necessary to hide (obfuscate) our PL/SQL source code, especially for security reasons, when, for example, we share our code with third parties. Traditionally, the WRAP tool has been used for this purpose, which we detail in this post. Starting with version 10g R2, it is possible to perform this action with the DBMS_DDL.WRAP package, which we will discuss in a post .
It is important to be aware of some of its limitations before applying it, especially in production environments. It is very important to have a copy of the PL/SQL code and version control before applying the "wrap" method to our code.
Basically, the limitations of the WRAP utility are as follows:
Obfuscated files, in those where we have used wrap, are not compatible between Oracle releases.
Wrap cannot be used in trigger code.
It is not secure for securing passwords or table names.
It does not detect syntax problems or code errors generated in our unobfuscated code.
The obfuscated code is longer than the original.
Wrap only obfuscates the body of a package or type, but not its specification.
To see how it works, we will create a simple function, which we will obfuscate with wrap.
CREATE OR REPLACE FUNCTION dia_de_hoy RETURN VARCHAR2 AS
BEGIN
RETURN TO_CHAR(SYSDATE, 'DD-MON-YYYYYY HH24:MI:SS');
END dia_de_hoy;
/
We check that the function is correct:
select today_day from dual;
TODAY_DAY
------- -------
31-AUG-2023 20:47:53
We copy the code of our function into the operating system.
[oracle u01]$ cattoday_date_function.sql
CREATE OR REPLACE FUNCTION today_date RETURN VARCHAR2 AS
BEGIN
RETURN TO_CHAR(SYSDATE, 'DD-MON-YYYY HH24:MI:SS');
END today_date;
/
We check in SQL-Developer that the appearance of our function is as usual, before applying the obfuscation.

In the operating system we launch the command to obfuscate the PL-SQL code.
La sintaxis es:
wrap iname=<fichero entrada> oname=<fichero de salida ofuscado>
[oracle u01]$ wrap iname=today's_function.sql oname=today's_function.out
PL/SQL Wrapper: Release 19.0.0.0.0 – Production on Thu Aug 31 21:17:23 2023
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle its affiliates. All rights reserved.
Processing function_today.sql to function_today.out
The utility will report the obfuscated code for execution.
CREATE OR REPLACE FUNCTION dia_de_hoy wrapped
a000000
1
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
8
74 b6
LH4SgLm3AMbYAySR+WVH9QmeSoAwg8eZgcfLCNL+Xlr6WV+uofByhWTD58CyvbKbXufHdMAz
uHRlCbh0i8DAMv7ShgmpoQLOxtYaIazv1kx2hHEyjndMcfUQc3P17zdnr2pqhduXsevFV1RM
66tN+j1y6a+V638ZlSoZaiQl7Pumz30sVg==
/
Copy the code and run it (SqlPlus, SqlDeveloper, etc).

From now on, all new sessions connecting to the database will not have access to the code in a readable form, and the code will be hidden from users.





