• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Decryption of file is taking too much time.

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How big is the file? RSA is a slow algorithm.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John, please UseCodeTags. You can edit your post to add them.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and wrapping a buffer around the input and output may make a significant difference, but it'll still be slow
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(And why is the decryption method named "doFinal"?)
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


That's a method in the javax.crypto.Cipher class.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, okay. I don't like that name.
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
john sal
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic