我不明白为什么这段代码会返回错误:
Data error (cyclic redundancy check). (Exception from HRESULT: 0x80070017)
因为 Silverlight 平台的等效代码不会引发异常。这是下面的 UWP c# 代码:
public static async Task<Stream> Decrypt(Stream source,
IBuffer easKey,IBuffer IV, byte[] masterKey)
{
try
{
SymmetricKeyAlgorithmProvider aes = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
if ((source.Length % aes.BlockLength) != 0)
{
var temp = new MemoryStream();
temp.SetLength(source.Length + (aes.BlockLength - source.Length % aes.BlockLength));
source.CopyTo(temp);
source = temp;
}
CryptographicKey symmKey = aes.CreateSymmetricKey(easKey);
var sarray = ((MemoryStream)source).ToArray();
IBuffer resultBuffer = CryptographicEngine.Decrypt(symmKey,sarray.AsBuffer(), IV);
byte[] result;
CryptographicBuffer.CopyToByteArray(resultBuffer, out result);
return new MemoryStream(result);
}
catch (Exception e)
{
await new MessageDialog(e.StackTrace, e.Message).ShowAsync();
}
return null;
}