2

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;
1
  • I've edited your question to make the actual exception you're receiving more obvious, please take note :)
    – tnw
    Commented Aug 11, 2014 at 20:36

1 Answer 1

0

CBC requires an IV (also a an IBuffer for CryptographicEngine.encrypt and CryptographicEngine.decrypt, so you cannot provide null. This is only written down for the encrypt function that the decrypt function references.

Not the answer you're looking for? Browse other questions tagged or ask your own question.