我试图编写一个解密字节数组的方法。
当我对数据进行实际解密时,我得到异常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;
答案 0 :(得分:0)
CBC需要IV(对IBuffer
和CryptographicEngine.encrypt
也是一个CryptographicEngine.decrypt
,因此您无法提供null
。这只是针对{{3} } decrypt
函数引用。