Updated May 19, 2023
Introduction to Oracle MD5
An Oracle MD5 function is a hash function which is used to access data integrity. MD5 stands for Message Digest Algorithm 5. MD5 is a cryptographic hash function which is commonly used to calculate the checksum of enter value and generate a 128-bit (16 Byte) hash value.
Points of Concentration:
- MD5 algorithm was developed in 1991 by cryptographer Ronald Rivest in 1991.
- MD5 function uses Message Digest Algorithm 5.
- MD5 function is commonly used in Cryptographic Hash Functions.
- MD5 function generates a 128-bit (16 Byte) Hash value.
- MD5 function returns 32 characters of Hexadecimal digits.
- MD5 function reduces cache memory usage at run time.
- MD5 has been used in a large variety of CRYPTOGRAPHIC applications.
- MD5 function calculates the checksum of enter value.
- MD5 function returns NULL if the input is NULL.
- MD5 function is a cryptographic algorithm that takes an input of arbitrary length and produces a message digest that is 128 bits long.
SELECT DBMS_OBFUSCATION_TOOLKIT.MD5(INPUT =>
UTL_RAW.CAST_TO_RAW (Column Name)) [Alias Name] FROM Table Name;
- DBMS_OBFUSCATION_TOOLKIT: It is an Oracle inbuilt package that can encrypt and decrypt data.
- MD5: It’s (Message Digest Algorithm 5) a function that can be accessed using DBMS_OBFUSCATION_TOOLKIT inbuilt package.
- UTL_RAW: This is a package. UTL denotes that it’s not specific to the database environment but can also be used in other environments.
- CAST_TO_RAW: This function casts a VARCHAR value to a VARBINARY value.
- Column Name: The column data that will be encrypted
- [Alias Name]: It’s optional. The alias name can be used to understand.
- Table Name: It’s the name of the table that will be used.
SELECT Ename, DBMS_OBFUSCATION_TOOLKIT.MD5 (INPUT =>
UTL_RAW.CAST_TO_RAW (Ename)) HASH_VALUE FROM Emp;
Examples to Implement Oracle MD5
Below are the examples mentioned:
In this section, we’ll see the implementation of Oracle MD5Function and its behavior. We will use the sample table (Employee) below with 14 records to understand the Oracle MD5Function behavior.
SELECT * Employee;
Oracle MD5 function on NUMBER data type column
SELECT Salary, DBMS_OBFUSCATION_TOOLKIT.MD5 (input =>
UTL_RAW.CAST_TO_RAW (Salary)) HASH_KEY FROM Employee;
Explanation: In the provided example, the MD5 function produced a cryptographic hash value for the data in the Salary column, which is a number data type.
Oracle MD5 function on VARCHAR2 data type column
SELECT Name, DBMS_OBFUSCATION_TOOLKIT.MD5 (input =>
UTL_RAW.CAST_TO_RAW (Name)) HASH_KEY FROM Employee;
Explanation: In the above example, the MD5 function generated a cryptographic hash value for Name column data which is the VARCHAR2 data type.
Oracle MD5 function on Date data type column
SELECT DOJ, DBMS_OBFUSCATION_TOOLKIT.MD5 (input =>
UTL_RAW.CAST_TO_RAW (DOJ)) HASH_KEY FROM Employee;
Explanation: The above examples show that the MD5 function can be applied to any data type. The MD5 function’s behavior can change when encountering NULL values or columns that contain NULL values. See some examples below
Oracle MD5 function on NULL
SELECT NULL, DBMS_OBFUSCATION_TOOLKIT.MD5 (input =>
UTL_RAW.CAST_TO_RAW (NULL)) HASH_KEY FROM DUAL;
Explanation: The above example throws an error when MD5 finds the null value. But here, Oracle throws 3 errors WHY? Because 1st error ORA-28231 says comes out because the function is not expecting a NULL value but getting a NULL value. 2nd and 3rd errors are the same but occur at different levels or lines; that’s why the package “DBMS_OBFUSCATION_TOOLKIT” throws twice. These two errors are the same because they consist of the same ORA number, which means they are for the same reason.
Oracle MD5 function with Miscellaneous value (NULL and NOT NULL value)
SELECT BONUS, DBMS_OBFUSCATION_TOOLKIT.MD5 (input =>
UTL_RAW.CAST_TO_RAW (Bonus)) HASH_KEY FROM Employee;
Explanation: The above example also throws the same error as the previous example because in this example “BONUS” column consists NULL value as well, and the MD5 function throws an error when it gets a NULL value. You can prevent the error by using the Oracle function.
Oracle MD5 function with Oracle NVL function to prevent the NULL value error
SELECT BONUS, DBMS_OBFUSCATION_TOOLKIT.MD5 (input =>
UTL_RAW.CAST_TO_RAW (NVL(Bonus, 0))) HASH_KEY FROM Employee;
Explanation: Using appropriate Oracle functions can help prevent NULL value errors. In the above example, the NVL function prevents the NULL value error because NVL provides zero “0” instead of NULL. After all, the HASH_KEY of Zero is precisely the same as the NULL value in the Bonus column.
Oracle MD5 function HASH value Length
SELECT BONUS, DBMS_OBFUSCATION_TOOLKIT.MD5(input =>
UTL_RAW.CAST_TO_RAW (NVL (Bonus,0)))) HASH_KEY_LENGTH FROM
- MD5 function is an excellent option to compare data or files between two or more data files.
- You can use Oracle functions in conjunction with the MD5 function.
- MD5 Function is available in the Oracle 12C version but under the package.
- As mentioned above that UTL_RAW is not specific to the database environment.
Use the Oracle MD5 function to produce a HASH value for the given data. That HASH value is a valuable key for assessing data integrity. MD5 is a cryptographic hash function that can be an excellent option to calculate a checksum of entering the value and generating a 128-bit (16 Byte) hash value. This is also a perfect option to compare files without inspecting the contents of those files.
This is a guide to Oracle MD5. Here we discuss an introduction to Oracle MD5, syntax with examples, and explanation. You can also go through our other related articles to learn more –