Oracle uses Java functions

Source: Internet
Author: User
Tags stringbuffer

Today we got a tricky job, providing data redaction to the three parties, operations that need to be done in Oracle, and here's a brief introduction to the functions written in Oracle using Java.

  • Compiled Java code, because the business party specifies the Java encryption algorithm, so only compile the prescribed encoding, here is special emphasis, the Oracle version comes with Java version number is generally low, my is 1.6 Java edition, so I have to compile into a 1.6 encoding:
  • vim SHA256. JAVA Public classsha256{ Public Staticstring getSHA256 (String input) throws Nosuchalgorithmexception,unsupportedencodingexception {messagedigest m D= Messagedigest.getinstance ("SHA-256"); Md.update (Input.getbytes (Charset.forname ("UTF-8"))); byteBytedata[] =md.digest (); StringBuffer SB=NewStringBuffer ();  for(inti =0; i < bytedata.length; i++) {sb.append (integer.tostring (bytedata[i)&0xFF) +0x100, -). SUBSTRING (1)); }        returnsb.tostring (); }}

    Compiling code

  • 1.6 1.6 sha256.java-encoding utf-8

    Load Java Execution Conditions (Oracle)

  • Su-'initjvm.sql' as sysdbasql>@./oracle/ product/11.2. 0/javavm/install/initjvm.sql;

    Load the. class file

  • Loadjava-r-f-o-user user/[email protected] ~/java/sha256. class

    Oracle Create function

  • CREATE OR REPLACE FUNCTION gnuhash_sha256 (string in VARCHAR2) RETURN VARCHAR2 as  '  sha256.getsha256 (java.lang.String) return java.lang.String';

    Validation results

Sekect gnuhash_sha256 ("12344556677778880099000DJDLSL");
    • Reference Document: http://jakub.wartak.pl/blog/?p=124

Oracle uses Java functions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.