Open AlexanderVolkovDA opened 2 years ago
Tried to investigate the issue. Have a guess that it is connected to mapping of Java androidx.security.crypto.EncryptedFile.openFileOutput()
return type from FileInputStream
to System.IO.Stream
. Somewhere in initialization it calls FileInputStream.getChannel()
that throws the exception.
But FileInputStream.getChannel()
looks like this:
@Override
public FileChannel getChannel() {
throw new UnsupportedOperationException("For encrypted files, please open the "
+ "relevant FileInput/FileOutputStream.");
}
Are you using Android.Support?
Tried to investigate the issue. Have a guess that it is connected to mapping of Java
androidx.security.crypto.EncryptedFile.openFileOutput()
return type fromFileInputStream
toSystem.IO.Stream
. Somewhere in initialization it callsFileInputStream.getChannel()
that throws the exception. ButFileInputStream.getChannel()
looks like this:@Override public FileChannel getChannel() { throw new UnsupportedOperationException("For encrypted files, please open the " + "relevant FileInput/FileOutputStream."); }
True. So, this is not issue with the bindings.
You need to see what must be done in java or kotlin (native) and then port that code. This exception would happen with java or kotlin.
this is not issue with the bindings.
I thought that the issue is in mapping to general System.IO.Stream
class instead more specific one (that is used in native).
You need to see what must be done in java or kotlin (native) and then port that code.
That's exactly what I've tried to do.
In java/kotlin call of androidx.security.crypto.EncryptedFile.openFileOutput()
does not lead to call of FileInputStream.getChannel()
. But in C# it does.
From android documentation sample usage is: https://developer.android.com/reference/androidx/security/crypto/EncryptedFile
String masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC);
File file = new File(context.getFilesDir(), "secret_data");
EncryptedFile encryptedFile = EncryptedFile.Builder(
file,
context,
masterKeyAlias,
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
).build();
// write to the encrypted file
FileOutputStream encryptedOutputStream = encryptedFile.openFileOutput();
// read the encrypted file
FileInputStream encryptedInputStream = encryptedFile.openFileInput();
So, as you can see in steps to reproduce, I tried to do the same in my code (just added small file existence check, usings and explicit types), but opening the file always throws this exception.
Maybe you could introduce FileInputStream
class, similar to native one with no getChannel()
call on file open?
Are you using Android.Support?
Yes, we use some:
Xamarin.Android.Support.Design 27.0.2.1 Xamarin.Android.Support.v4 27.0.2.1 Xamarin.Android.Support.v7.AppCompat 27.0.2.1 Xamarin.Android.Support.v7.CardView 27.0.2.1 Xamarin.Android.Support.v7.MediaRouter 27.0.2.1
I'm running into the same issue with the latest 1.1.0-alpha05.
Version Information
Describe your Issue:
When trying to open encrypted stream to read file with
AndroidX.Security.Crypto.EncryptedFile.OpenFileInput()
exception Java.Lang.UnsupportedOperationException with message: 'For encrypted files, please open the relevant FileInput/FileOutputStream.' is thrownSteps to Reproduce (with link to sample solution if possible):
Include any relevant Exception Stack traces, build logs, adb logs: