java stored procedure [message #340930] |
Fri, 15 August 2008 01:00 |
pmapc
Messages: 46 Registered: July 2008
|
Member |
|
|
I am using a java class as one of my packages in my application. in this class I want to decrypt some file that has been encrypted already in a java application.I used java APIs for both encryption and decryption but until now I didn't get any result.I really dont know where is the problem.Is there something wrong with the java class code, with the imports, with vesions,with oracle or something else.this class works properly in a java application and can decrypt my files without any problem.can anyone with more experience in this field help me to resolve the problem:
error message:
Error report:
ORA-29532: Java call terminated by uncaught Java exception: java.lang.NullPointerException
ORA-06512: at "XXXXXX.PROCESSLIBFILES", line 3
ORA-06512: at line 2
29532. 00000 - "Java call terminated by uncaught Java exception: %s"
*Cause: A Java exception or error was signaled and could not be
resolved by the Java code.
*Action: Modify Java code, if this behavior is not intended.
here is the procedure source code:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import oracle.jdbc.OracleCallableStatement;
import oracle.jdbc.OracleDriver;
import oracle.sql.BLOB;
public class DecryptBlob {
public static void ImportFile(String Location, String FileName, int randomid, String key) throws Exception {
InputStream bodyIns=null;
Connection conn = null;
OracleDriver ora = new OracleDriver();
conn = ora.defaultConnection();
File fileIn = new File("E:/Standards/s.pdf");
try {
SecretKeySpec spec = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, spec);
InputStream ins = new FileInputStream(fileIn);
File temp = new File("E:/Standards/s1.pdf");
OutputStream ous = new FileOutputStream(temp);
CipherInputStream cis = new CipherInputStream(ins, cipher);
byte[] buffer = new byte[0xFFFF];
for (int len; (len = cis.read(buffer)) > 0;) {
ous.write(buffer, 0, len);
}
InputStream bodyIn = new FileInputStream(temp);
ous.flush();
ous.close();
BLOB tempBlob = BLOB.createTemporary(conn, true, BLOB.DURATION_SESSION);
OutputStream bos = tempBlob.getBinaryOutputStream();
int b = 0;
while ((b = bodyIn.read()) != -1) {
bos.write(b);
}
bos.flush();
bos.close();
PreparedStatement ps = conn.prepareStatement("INSERT INTO BLOB_CONTENT (BID,BLOB_COLUMN,BLOB_SIZE) VALUES (?,?,?)");
ps.setInt(1, randomid);
ps.setInt(3, (int) fileIn.length());
ps.setBlob(2, tempBlob);
ps.executeUpdate();
ps.close();
conn.close();
}
catch (IOException iox) {
iox.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
}
}
}
thanks,
|
|
|
Re: java stored procedure [message #340935 is a reply to message #340930] |
Fri, 15 August 2008 01:18 |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
An NPE should be quite easy to debug.
Scatter your code with logging to see what happens.
For example: this E:/Standards/s.pdf is it a file on the server?
|
|
|
Re: java stored procedure [message #340945 is a reply to message #340935] |
Fri, 15 August 2008 02:20 |
pmapc
Messages: 46 Registered: July 2008
|
Member |
|
|
i changed the code to :
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import oracle.jdbc.OracleCallableStatement;
import oracle.jdbc.OracleDriver;
import oracle.sql.BLOB;
public class DecryptBlob {
public static void ImportFile(String Location, String FileName, int randomid, String key) throws Exception {
InputStream bodyIns=null;
Connection conn = null;
OracleDriver ora = new OracleDriver();
conn = ora.defaultConnection();
File fileIn = new File("E:/Standards/s.pdf");
try {
SecretKeySpec spec = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/NOPADDING");
cipher.init(Cipher.DECRYPT_MODE, spec);
InputStream ins = new FileInputStream(fileIn);
File temp = new File("E:/Standards/s1.pdf");
OutputStream ous = new FileOutputStream(temp);
CipherInputStream cis = new CipherInputStream(ins, cipher);
byte[] buffer = new byte[0xFFFF];
for (int len; (len = cis.read(buffer)) > 0;) {
ous.write(buffer, 0, len);
}
InputStream bodyIn = new FileInputStream(temp);
ous.flush();
ous.close();
BLOB tempBlob = BLOB.createTemporary(conn, true, BLOB.DURATION_SESSION);
OutputStream bos = tempBlob.getBinaryOutputStream();
int b = 0;
while ((b = bodyIn.read()) != -1) {
bos.write(b);
}
bos.flush();
bos.close();
PreparedStatement ps = conn.prepareStatement("INSERT INTO BLOB_CONTENT (BID,BLOB_COLUMN,BLOB_SIZE) VALUES (?,?,?)");
ps.setInt(1, randomid);
ps.setInt(3, (int) fileIn.length());
ps.setBlob(2, tempBlob);
ps.executeUpdate();
ps.close();
conn.close();
}
catch (IOException iox) {
iox.printStackTrace();
}
}
}
Error report:
ORA-29532: Java call terminated by uncaught Java exception: java.security.NoSuchAlgorithmException: Cannot find any provider supporting AES/ECB/NOPADDING
ORA-06512: at "XXXXXX.PROCESSLIBFILES", line 3
ORA-06512: at line 3
29532. 00000 - "Java call terminated by uncaught Java exception: %s"
*Cause: A Java exception or error was signaled and could not be
resolved by the Java code.
*Action: Modify Java code, if this behavior is not intended.
any idea?
|
|
|
|
|
|
|
Re: java stored procedure [message #340973 is a reply to message #340969] |
Fri, 15 August 2008 06:27 |
pmapc
Messages: 46 Registered: July 2008
|
Member |
|
|
Ok, let me describe what I want to do in more detail.
1- I need a client side application to encrypt some PDF files
2-I need to decrypt these encrypted file in apex using pl\sql after putting them on oracle server
at first we used a java application and dbms_crypto to encrypt files and then agin dbms_crypto to decrypt file in apex, by using this way everything workes fine , but the only problem was performance, for encrypt approximately 300 MB it took 15 minutes,because we have around 2 TB pdf files it was not a good way for us, so we decided to use java classes and APIs instead of dbms_crypto to decrypt and encrypt our files. now we encrypt the files with a sensible speed but can not decrypt them in apex environment(for decryption we are using thes class in my first post)
maybe again I'm in a wrong way, if you have any advice or suggestion please help me.
I really don't know what is the best solution for our problem.
Thanks,
|
|
|