Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call Oracle MD5 hash function?

I have below code. I am using Oracle 11g.

SELECT DBMS_OBFUSCATION_TOOLKIT.md5 (input => UTL_RAW.cast_to_raw(
  FIRST_NAME
  ||LAST_NAME
  )) md5_key ,
  FIRST_NAME ,
  LAST_NAME
FROM C_NAME_TAB
WHERE PKEY='1234'

How can i call this code? Can i directly execute this code in sqldeveloper?

like image 582
user755806 Avatar asked Mar 20 '14 12:03

user755806


People also ask

What is MD5 function in Oracle?

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 checksum of enter value and generating a 128 bit (16 Byte) hash value.

What is hash function in Oracle?

ORA_HASH is a function that computes a hash value for a given expression. This function is useful for operations such as analyzing a subset of data and generating a random sample. The expr argument determines the data for which you want Oracle Database to compute a hash value.

What is standard hash in Oracle?

STANDARD_HASH computes a hash value for a given expression using one of several hash algorithms that are defined and standardized by the National Institute of Standards and Technology.


2 Answers

In Oracle 12c you can use the function STANDARD_HASH. It does not require any additional privileges.

select standard_hash('foo', 'MD5') from dual;

The dbms_obfuscation_toolkit is deprecated (see Note here). You can use DBMS_CRYPTO directly:

select rawtohex(
    DBMS_CRYPTO.Hash (
        UTL_I18N.STRING_TO_RAW ('foo', 'AL32UTF8'),
        2)
    ) from dual;

Output:

ACBD18DB4CC2F85CEDEF654FCCC4A4D8

Add a lower function call if needed. More on DBMS_CRYPTO.

like image 95
tbone Avatar answered Sep 19 '22 12:09

tbone


I would do:

select DBMS_CRYPTO.HASH(rawtohex('foo') ,2) from dual;

output:

DBMS_CRYPTO.HASH(RAWTOHEX('FOO'),2)
--------------------------------------------------------------------------------
ACBD18DB4CC2F85CEDEF654FCCC4A4D8
like image 26
James Ding Avatar answered Sep 18 '22 12:09

James Ding