Forums Register Login

Decryption of file is taking too much time.

+Pie Number of slices to send: Send
I am facing a problem while decrypting a file.

The decryption process is too slow. The algorithm i am using is RSA public key encryption. Which is toooooo slow while decrypting the file.

I am doing the following steps ...

1) I read the encrypted data from the file
2) decrypt it and save it in a list
3) Then read the data from the list and write it back in the same file

"Step 3 is fine but decryption itself in step 2 is too slow."


public void Decryption(String fileName) {
try {
byte[] buffer = new byte[256];
ArrayList file = new ArrayList();
InputStream in = new FileInputStream(fileName);

while ((in.read(buffer)) != -1) {
file.add(dcipher.doFinal(buffer));
System.out.println(new String((byte[]) dcipher.doFinal(buffer),"UTF8"));
}

in.close();

FileWriter fw = new FileWriter(fileName);

for (int i = 0; i < file.size(); i++) {
fw.write(new String((byte[]) file.get(i),"UTF8"));
}
fw.close();

} catch (Exception e) {
e.printStackTrace();
}
}



Can somebody check the code and let me know if i am doing something wrong in this....
+Pie Number of slices to send: Send
How big is the file? RSA is a slow algorithm.
+Pie Number of slices to send: Send
John, please UseCodeTags. You can edit your post to add them.
+Pie Number of slices to send: Send
and wrapping a buffer around the input and output may make a significant difference, but it'll still be slow
+Pie Number of slices to send: Send
 

john sal wrote:I am facing a problem while decrypting a file.

The decryption process is too slow. The algorithm i am using is RSA public key encryption. Which is toooooo slow while decrypting the file.



It looks to me like you have a far bigger problem than it just being too slow. The whole encryption/decryption process looks flawed. How badly flawed can only be ascertained after seeing the whole code.

P.S. It is not normal to use RSA directly on files. It is more normal to use a hybrid approach using RSA to encrypt some random bytes that are used to create a session key for use in a symmetric algorithm such as AES.
+Pie Number of slices to send: Send
(And why is the decryption method named "doFinal"?)
+Pie Number of slices to send: Send
 

(And why is the decryption method named "doFinal"?)


That's a method in the javax.crypto.Cipher class.
+Pie Number of slices to send: Send
Oh, okay. I don't like that name.
+Pie Number of slices to send: Send
 

David Newton wrote:Oh, okay. I don't like that name.



You are not the first and certainly won't be the last to voice your dislike of that method name. There are various overloaded update() methods which can be called repeatedly until one has finish encrypting/decrypting and then one calls one of the overloaded doFinal() methods. To my mind, if one is going to have doFinal() methods then one should have doUpdate() methods and not update() methods. But it ain't going to be changed now!
+Pie Number of slices to send: Send
I think there is one hybrid approach in which data is encrypted using symmetic algo while the key is encrypted using RSA ... Can somebody let me know what exactly that approach is?
+Pie Number of slices to send: Send
 

john sal wrote:I think there is one hybrid approach in which data is encrypted using symmetic algo while the key is encrypted using RSA ... Can somebody let me know what exactly that approach is?



One hybrid approach is given in section 13.6 of "Practical Cryptography" by Fergusen and Schneier published by Wiley.
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1919 times.
Similar Threads
encrypt data in database
"javax.crypto.BadPaddingException: pad block corrupted" using BouncyCastle and DESede: How to avoid?
Need help in password Encryption and Decryption
encrypt data
IGNORE THE PREVIOUS BASE64 QUESTION!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:53:28.