RijndaelManaged расшифровка с использованием потока памяти из C # в PHP - PullRequest
0 голосов
/ 27 апреля 2018

Я хочу расшифровать файл Excel и сохранить данные в файл CSV. Какие методы я могу использовать в PHP?

У меня есть пример кода файла расшифровки в C #.

class Program
{
    static void Main(string[] args)
    {
       // THIS IS JUST A SAMPLE 16 BYTE KEY!!! //
       String secretKey = "050WC6tJuL@#*%^&";
       // For this demo, we are using a local file //
       String inputFile = "Sample.xlsx.encrypted";
       // ...and saving to a local file too!  
       String outputFile = "Sample.csv";
       try
        {
            // We are using an AES Crypto with ECB and PKCS7 Padding
            using (RijndaelManaged aes = new RijndaelManaged())
            {
                byte[] key = ASCIIEncoding.UTF8.GetBytes(secretKey);
                byte[] IV = ASCIIEncoding.UTF8.GetBytes(secretKey);

                aes.Mode = CipherMode.ECB;
                aes.Padding = PaddingMode.PKCS7;
                using (FileStream fsCrypt = new FileStream(inputFile, FileMode.Open))
                {
                    using (FileStream fsOut = new FileStream(outputFile, FileMode.Create))
                    {
                        using (ICryptoTransform decryptor = aes.CreateDecryptor(key, IV))
                        {
                            using (CryptoStream cs = new CryptoStream(fsCrypt, decryptor, CryptoStreamMode.Read))
                            {
                                int data;
                                while ((data = cs.ReadByte()) != -1)
                                {
                                    fsOut.WriteByte((byte)data);
                                }
                                cs.Flush();
                                cs.Close();
                                fsOut.Flush();
                                fsOut.Close();
                                fsCrypt.Close();
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            // failed to decrypt file
            Console.WriteLine("Errors : "+ex.Message);
        }
        Console.ReadLine();
    }
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...