Rijndael decryption in WinRT
本文关键字:WinRT in decryption Rijndael | 更新日期: 2023-09-27 18:17:26
我正在尝试编写一个解密字节数组的方法。
- 键是固定的和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;
CBC需要IV(也是CryptographicEngine.encrypt
和CryptographicEngine.decrypt
的IBuffer
),因此您不能提供null
。这只是为decrypt
函数引用的encrypt
函数写的。