MessageDigest-Salt Hash MD5 in Java and Oracle

Friday, July 1st, 2016 (0 Comment)

We have function generate password use MessageDigest class and algorithm Salt Hash MD5 in java.

We want to use this function in Oracle, we have two ways: compile java directly in oracle database and load java class into Oracle Database.

We have two generate salt hash: convert byte to hex and use encode of Base64.

1. Salt hash md5 and convert byte to hex

1.1. In java

We run with username and password

Output:

1.2. In Oracle

We have two ways:

a) load java class above into Oracle: use oracle’s jdk to compile

– Check version jdk by sql statement

– Use command line and move to folder Oracle’s jdk

– Complie JavaUtils.java file to JavaUtils.class file

– Load JavaUtils.class file into Oracle Database

Enter password and show detail :

– Check file class in oracle

b) Writing code java in Oracle database (PL\SQL)

– Copy content of java class above and run in PL|SQL

  • line 1: syntax create and compile java in oracle

– Create function use this java class

– Test this function

Output is the same java

2. Salt hash md5 and encode by Base64

This way is generate password like org.jboss.seam.security.passwordHash and function ChangePassword() of JpaIdentityStore class

2.1. In Java

  • line 24: change convertByteToHex(raw) to Base64.encodeBytes(raw)

– Run demo

Output

2.2. In Oracle

– Create function base on JavaUtils class above, and don’t forget grant privileges to user scheme

– Test demo

Output is like java’s result

2.3. Generate password in Oracle with algorithm MD5 (password + username) without java class

Testing with java class:

Testing without java class (only Oracle)

Output: Both are the same result

We can go to http://online-code-generator.com/md5-hash-with-optional-salt.php to test again

  • text : admin
  • check add a salt and select after this string
  • salt: 123

Result: 0192023a7bbd73250516f069df18b500

Tags: , , ,

Related Posts

database
How to create function return table or cursor in oracle
database
Create group user class by using object oriented plsql
database
Functions encrypt decrypt and checksum oracle
database
Create stored procedure pl/sql in oracle

Related Posts

database
How to create function return table or cursor in oracle
database
Create group user class by using object oriented plsql
database
Functions encrypt decrypt and checksum oracle
database
Create stored procedure pl/sql in oracle

Leave a Reply

Your email address will not be published. Required fields are marked *