0

I'm trying to implement Blowfish encryption, ECB mode, through BouncyCastle. The problem is that this code encrypts only first 8 bytes of the file. I don't know, what the problem might be. I've worked with BouncyCastle before.

I found that I'm not the one having this problem, but the solution here didn't help: Blowfish ECB Mode in BouncyCastle

The code is:

        byte[] fileIn = File.ReadAllBytes("file.txt"), fileOut = new byte[fileIn.Length];
        BlowfishEngine blowfishEngine = new BlowfishEngine();
        blowfishEngine.Init(true, new KeyParameter(Encoding.UTF8.GetBytes("ahoi")));
        blowfishEngine.ProcessBlock(fileIn, 0, fileOut, 0);
        File.WriteAllBytes("file2.txt", fileOut);
daralim
  • 183
  • 10
  • The `ProcessBlock` method, as you would likely assume from the name, processes a single block. The block size in Blowfish is 8 bytes. Can you figure out the rest from here? – Luke Joshua Park Sep 11 '18 at 00:03
  • Well, you called ProcessBlock and that's what it does. It processes one block, exactly 8 bytes, no more. You probably want PaddedBufferedBlockCipher, or, even easier, CipherStream. – President James K. Polk Sep 11 '18 at 00:35

0 Answers0