Last active
August 29, 2015 14:15
-
-
Save gkazior/7ceb3c6342a3dff0c3ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION fvGetHash512(pv_Arg IN VARCHAR2) | |
RETURN VARCHAR2 | |
IS LANGUAGE java name 'Hash512.getHash512(java.lang.String) return java.lang.String'; | |
/ | |
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Hash512" AS | |
import java.lang.*; | |
import java.security.MessageDigest; | |
public class Hash512 { | |
public static String getHash512(String arg) { | |
try { | |
final MessageDigest mda = MessageDigest.getInstance("SHA-512"); | |
final byte[] digest = mda.digest(arg.getBytes()); | |
final StringBuilder s = new StringBuilder(); | |
for (int i = 0; i < digest.length; i++) { | |
s.append(String.format("%02x", digest[i])); | |
} | |
return s.toString(); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
} | |
}; | |
/ | |
/* | |
The following select statement will return | |
309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f | |
*/ | |
SELECT fvGetHash512('hello world') | |
FROM DUAL | |
/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment