1

My .NET Core app is having to read files generated by an older application written in .NET Framework 4.6.x. This older application encrypts files using the System.Security.Cryptography.RijndaelManaged implementation. It uses RijndaelManaged.BlockSize = 256.

Turns out .NET Core only supports .BlockSize = 128. Unfortunately, I have no control over the older application (plus there are already a bunch of files that have been generated).

Is there anyway for a .NET Core app to read RijndaelManaged.BlockSize = 256 encrypted files?

Looking at the old application's code, it looks like it's been adapted from here.

AngryHacker
  • 59,598
  • 102
  • 325
  • 594

1 Answers1

1

Yes, you can include the software only Bouncy Castle libraries for .NET (in C#) into your project. This offers a RijndaelEngine where you can set the block size in the constructor. To implement CBC and padding you also need the CBCBlockCipher from modes and the right padding, see here for an example (just replace the engine and perform other changes to make it fit your use case).

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
  • 1
    Yeah, I found [this helper class](https://github.com/2Toad/Rijndael256/issues/13#issuecomment-637724412) that used Bouncy Castle. If anyone is going to use that, make sure that Derivation number is identical on Encrypt and Decrypt. – AngryHacker Jul 07 '21 at 16:50
  • 1
    Beware of stringified code though. A key is not the same thing as a passphrase and it should not be stored in a string at all. There are a lot of crappy "helper" classes out there, and I actually don't like these kind of wrapper classes at all. If you're going to write crypto classes, make them use-case specific. You don't want badly maintained / insecure wrapper classes all over in your code (I've been there). – Maarten Bodewes Jul 07 '21 at 22:10