Search code examples
c#cryptographybouncycastle

Bouncy Castle With Network Stream


I am trying to create a streaming cyrpto wrapper. I have a network connection that streams data down encrypted and I would like to decode it on the fly. Here is a link to the same functionality using the native crypto classes, but I need to do it with Bouncy Castle.

https://github.com/pdelvo/Pdelvo.Minecraft/blob/master/Pdelvo.Minecraft.Network/AesStream.cs

I tried using BufferedStreamCipher but could not figure out how to get it to work and could not find any examples. Any help would be greatly appreciated.

Thanks, Ray


Solution

  • So it appears to be AES in CFB8 mode, and you need a Stream.

    You can get the enc/dec cipher objects with

    CipherUtilities.GetCipher("AES/CFB8/NoPadding");

    You have to call Init on each, with

    new ParametersWithIV(new KeyParameter(keyBytes), ivBytes)

    Then you can wrap a (bidirectional) Stream with them:

    new CipherStream(innerStream, readCipher, writeCipher)

    That will probably get you started, but I am not %100 sure it will stream in quite the way you need. Give it a go though. Get back to me or post to the BC C# mailing list if there's something we can do to improve it.