AES-шифрование с CipherMode.ECB - PullRequest
       29

AES-шифрование с CipherMode.ECB

0 голосов
/ 26 марта 2019

Мне нужна помощь, чтобы запустить шифрование C # AES.

В моем примере у меня есть открытый текст, ключ и результат.

В онлайн-инструменте под названием http://aes.online-domain-tools.com/ он отлично работает.

По крайней мере, я знаю, что должен использовать CipherMode.ECB.

    public static byte[] encrypt_Aes()
    {
        // bData = sData
        byte[] bData = { 0xf4, 0xef, 0x30, 0x8f, 0x1a, 0xba, 0x3e, 0xff, 0x9f, 0x5a, 0x11, 0x71, 0x72, 0xea, 0xca, 0xbd };
        string sData = "ôï0º>ÿŸZqrêʽ";
        byte[] bKey = { 0x45, 0x6E, 0x4F, 0x63, 0x65, 0x61, 0x6E, 0x20, 0x47, 0x6D, 0x62, 0x48, 0x2E, 0x31, 0x33, 0x00 };
        byte[] bResult = { 0x9b, 0xe2, 0xe3, 0x5d, 0x5f, 0xe7, 0x85, 0x86, 0x45, 0x20, 0x05, 0x87, 0xdd, 0x3b, 0x51, 0x5c };

        byte[] bEencrypted;

        using (Aes aes = Aes.Create())
        {
            aes.KeySize = 256;
            aes.BlockSize = 128;
            aes.Padding = PaddingMode.Zeros;
            aes.Mode = CipherMode.ECB;

            aes.Key = bKey;

            // Create an encryptor to perform the stream transform.
            ICryptoTransform encryptor = aes.CreateEncryptor();

            // Create the streams used for encryption.
            using (MemoryStream msEncrypt = new MemoryStream())
            {
                using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                {
                    using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
                    {
                        //Write all data to the stream.
                        swEncrypt.Write(sData);
                    }
                    bEencrypted = msEncrypt.ToArray();
                }
            }
        }

        return bEencrypted;
    }
...