WinRT中的Rijndael解密

时间:2014-08-11 20:33:15

标签: c# encryption windows-runtime aes

我试图编写一个解密字节数组的方法。

  • 密钥已修复 24字节

当我对数据进行实际解密时,我得到异常The supplied user buffer is not valid for the requested operation,希望有人可以帮助我!

        // 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 个答案:

答案 0 :(得分:0)

CBC需要IV(对IBufferCryptographicEngine.encrypt也是一个CryptographicEngine.decrypt,因此您无法提供null。这只是针对{{3} } decrypt函数引用。