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