Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WinRT中的Rijndael解密_C#_Encryption_Windows Runtime_Aes - Fatal编程技术网

C# WinRT中的Rijndael解密

C# WinRT中的Rijndael解密,c#,encryption,windows-runtime,aes,C#,Encryption,Windows Runtime,Aes,我正在尝试编写一个解密字节数组的方法 密钥是固定的,长度为24字节 我得到一个异常,当我对数据进行实际解密时,提供的用户缓冲区对于请求的操作无效,希望有人能帮助我 // Get the key and put into IBuffers IBuffer keyBuffer = CryptographicBuffer.CreateFromByteArray(cKey); IBuffer plainText = CryptographicBuffer

我正在尝试编写一个解密字节数组的方法

密钥是固定的,长度为24字节 我得到一个异常,当我对数据进行实际解密时,提供的用户缓冲区对于请求的操作无效,希望有人能帮助我

        // 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;

CBC需要一个IV和一个IBuffer,用于CryptographicEngine.encrypt和CryptographicEngine.decrypt,因此不能提供null。这只写在解密函数引用的问题上。

我编辑了您的问题,使您收到的实际异常更加明显,请注意: