V
V
Vyacheslav Correct2021-11-06 14:46:24
PHP
Vyacheslav Correct, 2021-11-06 14:46:24

How to decode C# rijndael-256 in PHP?

Given:
There is a certain program that sends data via API, encrypted by rijndaelManaged with a block length and a key of 256. There are no source codes for the
program, it was written a long time ago and everything has already been lost, only the part that sends the data remains. It needs to be decoded on the PHP side.

public static string EncryptMessage(byte[] text, string key)
    {
      RijndaelManaged rijndaelManaged = new RijndaelManaged();
      rijndaelManaged.KeySize = 256;
      rijndaelManaged.BlockSize = 256;
      rijndaelManaged.Padding = PaddingMode.Zeros;
      rijndaelManaged.Mode = CipherMode.CBC;
      rijndaelManaged.Key = Encoding.Default.GetBytes(key);
      rijndaelManaged.GenerateIV();
      string str = "-[--IV-[-" + Encoding.Default.GetString(rijndaelManaged.IV);
      ICryptoTransform encryptor = rijndaelManaged.CreateEncryptor(rijndaelManaged.Key, rijndaelManaged.IV);
      byte[] inputBuffer = text;
      return Convert.ToBase64String(Encoding.Default.GetBytes(Encoding.Default.GetString(encryptor.TransformFinalBlock(inputBuffer, 0, inputBuffer.Length)) + str));
    }


The problem is that in PHP - AES-256-CBC is not suitable, as these are different algorithms, judging by the information on the Internet.
PHP version 7.3. So no mcrypt_decrypt.
I was thinking of writing a small decoder service in C#, but in the current version they have removed the ability to control the length of the block, leaving it 128. This code does not work now. Maybe someone faced a similar problem, is there any solution? Maybe in another language there are solutions other than PHP? Or maybe I just did not find a solution in PHP
rijndaelManaged.BlockSize = 256;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-11-06
@Adler_lug

If the C# program is not obfuscated, then with a high probability it can be corrected without having the source code. Everything depends on the complexity of the program and the ability of the "reverse". This needs to be addressed here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question