Search code examples
c#performanceencryptionaesbouncycastle

How can I improve cyphering speed of the Bouncy Castle API?


I'm developing a software in C#, until now I was using the cryptographic library included in .NET (especially AesCryptoServiceProvider), but now I've special needs and I need to move to the Bouncy Castle API's. I've done some tests and I found out that these API are slower in comparison of what it's included in the .NET framework. Any idea on how to improve their performance? This is the cipher that I'm using: IBufferedCipher cipher = new CtsBlockCipher(new CbcBlockCipher(new AesFastEngine()));

To be more specific, I need to move to the Bouncy Castle API's because I need both input and output file with the same length and the .NET RijndaelManaged (the only class that can assure that kind of behavior) is way slower than AesCryptoServiceProvider.

To encrypt a file of 1.7MB with AesCryptoServiceProvider it takes about 40ms in my machine and about 170ms with Bouncy Castle. It doesn't look like much, but I need to use this software in a server with hundreds of requests per minutes...

Thank you very much!!


Solution

  • Since it sounds like you need a stream cipher, maybe look into Salsa20. It's supposed to be fast in general. And Bouncy Castle has an implementation (Salsa20Engine).