C# WinRT中的Rijndael解密
我正在尝试编写一个解密字节数组的方法 密钥是固定的,长度为24字节 我得到一个异常,当我对数据进行实际解密时,提供的用户缓冲区对于请求的操作无效,希望有人能帮助我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
// 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。这只写在解密函数引用的问题上。我编辑了您的问题,使您收到的实际异常更加明显,请注意: