DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Manual Sharding in PostgreSQL: A Step-by-Step Implementation Guide
  • Why Database Migrations Take Months and How to Speed Them Up
  • Unmasking Entity-Based Data Masking: Best Practices 2025
  • How Trustworthy Is Big Data?

Trending

  • Blue Skies Ahead: An AI Case Study on LLM Use for a Graph Theory Related Application
  • Distributed Consensus: Paxos vs. Raft and Modern Implementations
  • Mastering Fluent Bit: Installing and Configuring Fluent Bit on Kubernetes (Part 3)
  • AI Speaks for the World... But Whose Humanity Does It Learn From?
  1. DZone
  2. Data Engineering
  3. Databases
  4. Hashing With SHA-256 in Oracle 11g R2

Hashing With SHA-256 in Oracle 11g R2

Want to bring the SHA-256 Hashing algorithm to Oracle 11g R2? Here is how to implement a hashing method that isn't natively supported by the database.

By 
Emrah Mete user avatar
Emrah Mete
·
Feb. 14, 18 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
49.9K Views

Join the DZone community and get the full member experience.

Join For Free

As you know, Oracle offers some support for encryption and hashing in the database. Taking advantage of this underlying infrastructure offered by Oracle allows us to accelerate our business considerably.

With Oracle 11g R2, we can see that there are many ways to look at the structure provided to the user.


When we look at the list, we see that Oracle 11g R2 does not have every method. One of these methods is the SHA-256 Hashing algorithm. This support was provided with Oracle 12c, but if we do not have the option to upgrade the database, we can implement the SHA-256 method indirectly.

To implement this method, I will use the ability to create Java classes within the Oracle database. So in summary, I will do the data hashing with the help of a Java code that I write in the database. Later, I will wrap this java code with a PL/SQL function and use it as a normal SQL function.

First, I create the Java class in the database that will implement the SHA-256 method:

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED test."calcsha"
   AS import java.security.MessageDigest; 
public class calcsha2 
    {
        static public String fncsha(String inputVal) throws Exception
        {           
            MessageDigest myDigest = MessageDigest.getInstance("SHA-256");        
            myDigest.update(inputVal.getBytes());
            byte[] dataBytes = myDigest.digest();
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < dataBytes.length; i++) {
             sb.append(Integer.toString((dataBytes[i])).substring(1));
            }        

            StringBuffer hexString = new StringBuffer();
            for (int i=0;i<dataBytes.length;i++) {
                String hex=Integer.toHexString(0xff & dataBytes[i]);
                    if(hex.length()==1) hexString.append('0');
                    hexString.append(hex);
            }
            String retParam = hexString.toString();
            return retParam;           
        }    
    }


We created our Java resource in the database. Now let's write a PL/SQL function that will wrap this resource:

CREATE OR REPLACE FUNCTION test.hash_sha256 (txt varchar2)
RETURN VARCHAR2
AS
LANGUAGE JAVA
NAME 'calcsha2.fncsha(java.lang.String) return String';


We wrote the PL/SQL function. Now we can test it:

select hash_sha256('123456789') from dual;



HASH_SHA256('123456789')                                                        
-----------------------------------------------------------------
15e2b0d3c33891ebb0f1ef609ec419420c20e320ce94c65fbc8c3312448eb225                
1 row selected.


Yes, with this example we have implemented a hashing method that is not supported by Oracle 11g R2.

Database

Opinions expressed by DZone contributors are their own.

Related

  • Manual Sharding in PostgreSQL: A Step-by-Step Implementation Guide
  • Why Database Migrations Take Months and How to Speed Them Up
  • Unmasking Entity-Based Data Masking: Best Practices 2025
  • How Trustworthy Is Big Data?

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!