Hi,
I am trying to call
java method from oracle function to get hash code, please
refer the the code-
java code:
create or replace and compile java source named lookUpHash AS
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Encoder;
public class LookUpHash {
public static
String getLHash(String colValue) {
String result = "";
try{
long l = 0;
String encryptValue = encrypt(colValue);
l = getHashCode(encryptValue);
result = String.valueOf(l);
}catch(Exception e){
e.printStackTrace();
}
return result;
}
public static String encrypt(String plainText){
BASE64Encoder encoder = null;
String encrypted = null;
byte[] keyBytes = "1234567890123456".getBytes();
try
{
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(256);
SecretKey skey = keyGen.generateKey();
SecretKeySpec KeySpec = new SecretKeySpec(keyBytes, "AES");
Cipher AesCipher = Cipher.getInstance(skey.getAlgorithm());
AesCipher.init(Cipher.ENCRYPT_MODE, KeySpec);
encoder = new BASE64Encoder();
byte[] CipherText = AesCipher.doFinal(plainText.getBytes());
encrypted = encoder.encode(CipherText);
return encrypted;
}
catch(Exception e){
System.out.println("Exception in encrypt: "+e);
e.printStackTrace();
}
return encrypted;
}
public static long getHashCode(String value)
{
char val[] = value.toCharArray();
long hash = 1;
int len = value.length();
int j = 1;
for (int i = 0; i < len; i++ )
{
hash = 1 + hash + (++j * 500) + val[i];
}
return hash;
}
}
and oracle function is :
create or replace
FUNCTION oo(name VARCHAR2) RETURN VARCHAR2
AS LANGUAGE JAVA NAME 'HashSomu.getLHash(java.lang.String) return String';
but it is gave: ORA-29532: Java call terminated by uncaught Java exception: java.lang.NullPointerException
I am sure it is return null value from encrypt().
please send me solution if any bady had faced this kind of problem.
Thank you