0

In the CBC decryption loop I'm dealing with small (< 32 bytes) byte chunks so I can't use a StringBuilder because the Heap blows up. I figure I should take the decrypted bytes and dump them into some kind of buffered array. At this point I'm confused about how to setup and populate an InputStreamReader from these bytes. If I can populate this InputStreamReader then I want to wrap a BufferedReader around it. I then plan to read from the BufferedReader one line at a time because my text processing just needs to operate on one line at a time. I don't want to write any data to disk during this process. I'm just super confused about what to do with bytes that I'm getting from my CBC decryption loop. They obviously need to buffer (since a line of my text file is probably 20 times the size of a decrypted chunk) but I'm confused about the buffer that will act as the middleman. I'm using BouncyCastle but that piece of the puzzle isn't really causing me issues at the moment. ~Thanks for the newbie help.

fooledbyprimes
  • 999
  • 1
  • 11
  • 29
  • Note: I haven't looked into any BouncyCastle conveniences because I want to learn the buffer/stream basics provided by Java. But I am certainly open to ideas based on BC's tools. – fooledbyprimes Mar 11 '13 at 23:50

1 Answers1

2

Take the bytes from your decryption block, and dump them in to a PipedOutputStream. Then create a PipedInputStream from that, wrap appropriately, and feed it to your other code.

This is best done in two separate threads. It may work in one, but you'd have to be careful to not block (notably the reading), or you'll get stuck.

Or you could write your own custom InputStream implementation over your decrypter.

Will Hartung
  • 115,893
  • 19
  • 128
  • 203