UWP Не могу зашифровать в AES CBC

207
25 апреля 2018, 04:12

Пытаюсь зашифровать byte[] в AES CBC. Конечный буфер (bufferEncrypt) имеет значение NULL.

private byte[] Encrypt(byte[] data)
{
    byte[] secretKey = new byte[] { 1, 2, 3 };
    IBuffer key = Convert.FromBase64String(Convert.ToBase64String(secretKey.ToArray()).ToString()).AsBuffer();
    Debug.WriteLine(key.Length);
    SymmetricKeyAlgorithmProvider algorithmProvider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbc);
    CryptographicKey cryptographicKey = algorithmProvider.CreateSymmetricKey(key);
    IBuffer bufferEncrypt = CryptographicEngine.Encrypt(cryptographicKey, data.AsBuffer(), null);
    return bufferEncrypt.ToArray();
}

Вот что показывает отладчик (Имя, Значение, Тип):

+       this    {Project.Auth}  Project.Auth
+       data    {byte[15]}  byte[]
bufferEncrypt   null    Windows.Storage.Streams.IBuffer
+       cryptographicKey    {Windows.Security.Cryptography.Core.CryptographicKey}   Windows.Security.Cryptography.Core.CryptographicKey
+       key {System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBuffer}    Windows.Storage.Streams.IBuffer {System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBuffer}
+       algorithmProvider   {Windows.Security.Cryptography.Core.SymmetricKeyAlgorithmProvider}  Windows.Security.Cryptography.Core.SymmetricKeyAlgorithmProvider
+       SecretKey   Count = 16  System.Collections.Generic.List<byte>

В чем моя ошибка?

READ ALSO
Как подключить dll(c++) к с#?

Как подключить dll(c++) к с#?

Знаю, что популярная проблемаНо нужно срочно, а я вообще не бум-бум

197
Передача DateTime в URL методу

Передача DateTime в URL методу

Есть метод контроллера сервера Refresh(DateTime? Date) Есть метод jQuery который отправляет ajax-запрос по URL наподобие http://localhost:1234/Home/Refresh?Date=2304

175
Выгрузить привязанные данные в word

Выгрузить привязанные данные в word

Подскажите пожалуйста, как (c# winforms vs2010) обратиться (чтобы выгрузить в word) к привязанным данным "Value_1 и Value_2"? Те

190
C#, Visual Studio 2017, Работа с Word (Office 365)

C#, Visual Studio 2017, Работа с Word (Office 365)

Пытаюсь запустить простейший код консольного приложения:

203