Hello Darren,

 

That’s VB.net but shouldn’t be a problem, I think. 

 

Dim buffer() As Byte

Dim cipherParameters As ICipherParameters = New Parameters.ParametersWithIV(New 
Parameters.KeyParameter(key), iv)

Dim cipher As BufferedBlockCipher = New Paddings.PaddedBufferedBlockCipher(New 
Modes.CbcBlockCipher(New Engines.AesEngine), New Paddings.Pkcs7Padding)

cipher.Init(True, cipherParameters)

 

Using br As New BinaryReader(New FileStream(sourceFile, FileMode.Open, 
FileAccess.Read))

                Using bw As New BinaryWriter(New FileStream(targetFile, 
FileMode.Create, FileAccess.Write))

                               Do While br.BaseStream.Position < 
br.BaseStream.Length

                                               buffer = 
br.ReadBytes(AES_BLOCK_SIZE)

                                               If buffer.Length < 
AES_BLOCK_SIZE Then

                                                               
bw.Write(cipher.DoFinal(buffer))

                                               Else

                                                               buffer = 
cipher.ProcessBytes(buffer)

                                                               bw.Write(buffer)

                                               End If

                               Loop

                End Using 'bw

End Using 'br

 

Von: DARREN ARSENAULT [mailto:darren....@rogers.com] 
Gesendet: Donnerstag, 17. September 2015 16:33
An: dev-crypto-csharp@bouncycastle.org
Betreff: [dev-crypto-csharp] NEED HELP ENCRYPTING/DECRYPTING LARGE FILES

 

I have searched for documentation on my problem, but found no answers—only 
others asking a similar question.

(FYI- I am a newbie to encryption, and am learning as I go.)

 

I have inherited a set of classes that performs encryption/decryption using 
AesEngine and PaddedBufferedBlockCipher. The code works great, but is designed 
to handle files that will fit into memory, processed in a single operation. 

 

I need to update this code to work on very large (hundreds of MBs, maybe even 
GBs) files, and am unsure what to do. My first thought is that I need to use 
streams for the input and output, but I have found no documentation on how this 
might be accomplished. In the API I see that there is a BufferedStreamCipher 
class, but I am not sure if this is what I am looking for, or how to 
instantiate it for my needs. Again, I find little information online. 

 

Does this functionality exist? And, if so, can anyone point me towards 
documentation or examples on it please?

 

Thank you very much for your time. Good-day, and be well.

 

Darren Arsenault 

 

Reply via email to