简体   繁体   中英

Visual Studio app working before publish on store and not after publishing

This code is working well when app not published on Microsoft store. But gives "Padding is invalid and can not be removed" error after publishing. All key and salt IV are checked and are same. what is wrong please help. Or suggest other code. It is mobile phone 8.1 and windows mobile 10.0 app. Source file is in SD card and destination is in Application's local folder.

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());
}

The problem was in accessing srcfile from SD card. The access was denied and that failed filestream to get anydata to decrypt. Hence it decrypts null data and gives padding error. I got the point because I try to copy copy file via filestream and then to decrypt. Copying file failed and gave access denied error. Can any one help in why access to path of file in SD card failed. the error is https://www.microsoft.com/getsilverlight/DllResourceIDs/Default.aspx?Version=4.0.30508.0&File=mscorlib.dll&Key=UnauthorizedAccess_IODenied_Path . The app accessing SD card file before publishing. All permissions are included.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM