BitmapFactory.DecodeFile returns null on Android version Lollipop and higher (Xamarin Android)?

Sawing the app on Xamarin. Normal activity with the vyuha. Encrypt files using the AES algorithm, the encryption method used here is a (decoding similar):
public static void Encode(string inputPath, string outputPath, string _key, string _iv)
{
 using (Aes aes = Aes.Create())
{
 aes.Key = Encoding.Unicode.GetBytes(_key);
 aes.IV = Encoding.Unicode.GetBytes(_iv);

 using (Stream s = File.OpenWrite(outputPath))
{
 using (CryptoStream cs = new CryptoStream(s, aes.CreateEncryptor(), CryptoStreamMode.Write))
{
 byte[] data = File.ReadAllBytes(inputPath);
 cs.Write(data, 0, data.Length);
}
}
}
 }


The paradox is that on Android 4.4, everything works perfectly. Files (including non-images, just text) encrypted and decrypted perfectly. The Method BitmapFactory.DecodeFile correctly generates a picture from the decoded files.
But on Android versions 5.0 and above there is the following:
text files normally generated, encrypted and decrypted. But with pictures trouble - BitmapFactory.DecodeFile returns null. This occurs if you feed him the decrypted image. With the previously unencrypted images this method is working properly.

In what direction to dig?
April 19th 20 at 12:42
1 answer
April 19th 20 at 12:44
Solution
The problem is solved. The trouble was with the method of encryption that Xamarin has ported probably not very efficiently. Helped transition to this encryption method. It is unsafe, but as a starting point for improvements will do.

public static void Encode(string inputPath, string outputPath, string _key, string _iv)
{
 byte[] inp = System.IO.File.ReadAllBytes(inputPath);

 Javax.Crypto.Spec.SecretKeySpec sks = new Javax.Crypto.Spec.SecretKeySpec(System.Text.Encoding.Unicode.GetBytes(_key), "AES");
 Javax.Crypto.Cipher cipher = Javax.Crypto.Cipher.GetInstance("AES/CTS/PKCS7Padding");
 cipher.Init(Javax.Crypto.CipherMode.EncryptMode, sks, new IvParameterSpec(System.Text.Encoding.Unicode.GetBytes(_iv)));

 byte[] res = cipher.DoFinal(inp);

 System.IO.File.WriteAllBytes(outputPath, res);
 }

Find more questions by tags XamarinC#EncryptionAndroid