2
此代碼在Microsoft商店中未發佈應用程序時運行良好。但發佈後出現「填充無效且無法刪除」的錯誤。 所有密鑰和鹽IV都被檢查並且相同。有什麼不對,請幫忙。或者建議其他代碼。它是手機8.1和Windows Mobile 10.0應用程序。 源文件位於SD卡中,目標位於應用程序的本地文件夾中。Visual Studio應用程序在發佈之前在商店中發佈並且不在發佈之後
int Iterations = 1000;
AesManaged aes = new AesManaged();
aes.BlockSize = aes.LegalBlockSizes[0].MaxSize;
aes.KeySize = aes.LegalKeySizes[0].MaxSize;
byte[] salt = GetBytes(SaltKey);
Rfc2898DeriveBytes key = new Rfc2898DeriveBytes(SKey, salt, Iterations);
aes.Key = key.GetBytes(aes.KeySize/8);
aes.IV = key.GetBytes(aes.BlockSize/8);
ICryptoTransform transform = aes.CreateDecryptor(aes.Key, aes.IV);
try
{
using (FileStream dest = new FileStream(destFilename, FileMode.CreateNew, FileAccess.Write, FileShare.None))
{
using (CryptoStream cryptoStream = new CryptoStream(dest, transform, CryptoStreamMode.Write))
{
using (FileStream source = new FileStream(srcFilename, FileMode.Open, FileAccess.Read, FileShare.Read))
{
source.CopyTo(cryptoStream);
}
}
}
}
catch (Exception exception)
{
//return "Decryption failed : " + exception.Message.ToString();
System.Diagnostics.Debug.WriteLine("Decryption failed : " + exception.Message.ToString());
//throw new ApplicationException("Decryption failed.", exception);
MessageBox.Show("Decryption failed : " + exception.Message.ToString());
}