• 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

Java Decryption by cipher.update?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to decrypt files by Java and below codes work. However it will have OutOfMemory exception when decrypting large files. I researched and seems like my problem is that I am reading the whole encrypted file into memory. People suggested to use cipher.update. However if I switch to that, the program will just not respond.

How can I solve my problem? Thanks.

 
Ranch Hand
Posts: 180
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm , i suggest to use Scatter/Gather contained by java N I O package,  Scatter is a read from Channel, and  is  read data operation that permits  read data into  multiple buffers and Gather is a write Channel that indulges  write operation that writes data from multiple buffers
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read in the data using a CipherInputStream.
Write the decrypted data out as you read it in.
That way you only hold whatever size of buffer you decide to use.
 
Felix Wong
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Houssam El wrote:Hmm , i suggest to use Scatter/Gather contained by java N I O package,  Scatter is a read from Channel, and  is  read data operation that permits  read data into  multiple buffers and Gather is a write Channel that indulges  write operation that writes data from multiple buffers



Thanks for your reply.

I found an example of how to use it but I cannot figure out how this can be used in my codes.

 
Houssam El
Ranch Hand
Posts: 180
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Felix Wong wrote:

Houssam El wrote:Hmm , i suggest to use Scatter/Gather contained by java N I O package,  Scatter is a read from Channel, and  is  read data operation that permits  read data into  multiple buffers and Gather is a write Channel that indulges  write operation that writes data from multiple buffers



Thanks for your reply.

I found an example of how to use it but I cannot figure out how this can be used in my codes.



first of all , you will specify the file that you want to read , and invoke get channel method on the file input stream , then you will use Scatter
don't forget you must know the encrypt key to decrypt the file

 
Felix Wong
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Read in the data using a CipherInputStream.
Write the decrypted data out as you read it in.
That way you only hold whatever size of buffer you decide to use.



I tried CipherInputStream. I did not encounter any error but the output .gz file is corrputed. Did I miss anything?

 
Houssam El
Ranch Hand
Posts: 180
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Felix Wong wrote:

Dave Tolls wrote:Read in the data using a CipherInputStream.
Write the decrypted data out as you read it in.
That way you only hold whatever size of buffer you decide to use.



I tried CipherInputStream. I did not encounter any error but the output .gz file is corrputed. Did I miss anything?





try to use this scheme ,

 
Houssam El
Ranch Hand
Posts: 180
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Houssam El wrote:

Felix Wong wrote:

Dave Tolls wrote:Read in the data using a CipherInputStream.
Write the decrypted data out as you read it in.
That way you only hold whatever size of buffer you decide to use.



I tried CipherInputStream. I did not encounter any error but the output .gz file is corrputed. Did I miss anything?





try to use this scheme ,



i forget one point , when you wanna catch exceptions thrown, use General Security Exception rather than declare each exception
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Felix Wong wrote:
I tried CipherInputStream. I did not encounter any error but the output .gz file is corrputed. Did I miss anything?



I don't see the input stream there.
You seem to be writing all into a single data buffer as before.
 
Felix Wong
Greenhorn
Posts: 14
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I finally solved the issue with below codes.
 
Houssam El
Ranch Hand
Posts: 180
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Felix Wong wrote:I finally solved the issue . . .




cool bro , keep continue , i m happy to hear that
 
reply
    Bookmark Topic Watch Topic
  • New Topic