I'm trying to write a method that decrypts a byte array.
- the key is fixed and 24 bytes long
I get an exception The supplied user buffer is not valid for the requested operation
when I do the actual decryption of the data, I hope someone can help me!
// Get the key and put into IBuffers
IBuffer keyBuffer = CryptographicBuffer.CreateFromByteArray(cKey);
IBuffer plainText = CryptographicBuffer.CreateFromByteArray(cData);
byte[] decryptedData;
// Setup an AES key, using AES in CBC mode and applying PKCS#7 padding on the input
SymmetricKeyAlgorithmProvider aesProvider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcbPkcs7);
CryptographicKey aesKeySymm = aesProvider.CreateSymmetricKey(keyBuffer);
// Decrypt the data and convert it to byte array
// EXCEPTION ON THIS LINE: "The supplied user buffer is not valid for the requested operation."
IBuffer decrypted = CryptographicEngine.Decrypt(aesKeySymm, plainText, null);
CryptographicBuffer.CopyToByteArray(decrypted, out decryptedData);
return decryptedData;