0

I have the next code that perfectly works encrypting and decrypting in net framework even with a invalid key for RijndaelManaged, but now in the netCore it doesn’t work because its needs a 16 bytes key, I want to recreate the key that the library in net frameworks makes with a key expansion to decrypt in a net core app, but I don’t now how

I found a similar problem but in PHP here RijndaelManaged.CreateEncryptor key expansion, but it says “just chop off the last 2 bytes” but of what? and how I complete the rest of bytes?

//Code tha works in the framework app
///8 bytes
_key = System.Text.ASCIIEncoding.UTF8.GetBytes("abcdefgh");

//16 bytes
_iv = System.Text.ASCIIEncoding.UTF8.GetBytes("abcdefghijklmnop");
_provider = new RijndaelManaged();
_provider.Mode = CipherMode.CBC;
_provider.KeySize = 128;
_provider.CreateEncryptor(_key, _iv)
tuxos
  • 1
  • Um, yes, a 128 bit encryption algorithm DOES need a 128 bit key. If you insist on using a string as your key then run it through a hashing algorithm first, and take your 16 bytes from the output of that. You still have WAY less than 128 bits of entropy for your encryption. – Steve Todd May 08 '19 at 16:28
  • As for making a library compatible with your current code, have you tried zero filling the remaining 8 bytes? – Steve Todd May 08 '19 at 16:29
  • Yes it needs a 128bits key but for some reason it works with a 64bits key in the net framework library because of a “feature” that expand the key, yes I tried filling with zero the last 8 bytes and at the begin too, but it doesn’t work – tuxos May 08 '19 at 18:49
  • The other options to try are to repeat the string twice, or take the last 8 bytes of the IV. If they doesn't work then you're going to have to bite the bullet and change the old code/algorithm to work correctly (but lose compatibility with the existing passwords). – Steve Todd May 09 '19 at 08:31
  • A little research later, and this may prove useful to you: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.paddingmode?view=netframework-4.8 – Steve Todd May 09 '19 at 08:38

0 Answers0