How to open encrypted file in xamarin forms app?

I want to encrypt data in internal storage and than I want to open this data with a viewer. I use custom renderer in ios and android for document viewer. (For example in android: I get internal storage path and I create uri and than I open intent with uri. Or for example in ios: I create QLPreviewController with file path and I open with UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController). So I need a file path for preview a file. If I want to preview a encrpyted file, I need decrypt and save this way in internal storage. But I don't want to save any decrypted file on phone external or internal storage.

Is there a way to open the file from ram without saving it to the phone? Or is there a way to open the file from encrypted data?

Sorry for my bad English.

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    Is there a way to open the file from ram without saving it to the phone?

    You could store the file in iCloud via File app , please check https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/file-system#sharing-with-the-files-app .

    Or is there a way to open the file from encrypted data?

    Add the application which can open(read) file with encrypted data into UIDocumentPickerViewController .

  • pelinalpppelinalpp Member ✭✭
    edited October 2019

    I guess I couldn't fully explain my problem. I don't want to leave the footprint of unencrypted data anywhere. Only I want to save encrypted data. If my data is unencrypted, I don't want to save it in icloud also. Or I want to open directly from ram, without save anywhere.

    So I need to open directly encrypted data or If it is unencrypted, I need to open from ram. Or if you have any other suggestions I can get it.

  • RadoslawKubasRadoslawKubas USMember ✭✭

    Maybe using MemoryStream will be helpful?

  • pelinalpppelinalpp Member ✭✭

    Yes, that's exactly what I want. But I didn't open only memory stream or byte array.

    I'm using this to preview:

    void IDocumentView.DocumentView(string filepath, string title)
    {
        string[] filePathList = filepath.Split('.');
            String extension = filePathList[filePathList.Length - 1];
            String mimeTypeMap = MimeTypeMap.GetFileExtensionFromUrl(extension.ToLower());
            String mime = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(mimeTypeMap);
    
        Java.IO.File extFile = new Java.IO.File(filepath);
        if (System.IO.File.Exists(extFile.AbsolutePath))
            {
                Intent intent = new Intent();
                intent.SetAction(Android.Content.Intent.ActionView);
    
            Android.Net.Uri uri;
            string fileprovider = CrossCurrentActivity.Current.Activity.PackageName + ".fileprovider";
                    uri = FileProvider.GetUriForFile(CrossCurrentActivity.Current.AppContext, fileprovider, extFile);
                    intent.AddFlags(ActivityFlags.NewTask);
                    intent.AddFlags(ActivityFlags.GrantReadUriPermission);
    
                    intent.SetDataAndType(uri, mime);
                    CrossCurrentActivity.Current.Activity.StartActivityForResult(intent, 10);
        }
    }
    

    Or ios:

    void IDocumentView.DocumentView(string file, string title)
    {
                UIApplication.SharedApplication.InvokeOnMainThread(() =>
                {
                    PdfPreviewController previewController = new PdfPreviewController();
    
                    if (File.Exists(file))
                    {
                        previewController.DataSource = new PDFPreviewControllerDataSource(NSUrl.FromFilename(file), title);
                        UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(previewController, true, null);
    
                    }
                });
    }
    

    So I need a file path to preview a file. I can't preview with memory stream. I couldn't find how to do this. How to preview memory stream without save anywhere in xamarin forms?

  • RadoslawKubasRadoslawKubas USMember ✭✭

    How about using for preview Syncfusion.SfPdfViewer? https://help.syncfusion.com/xamarin/sfpdfviewer/overview

    I've never used it, but it seems to use Stream as pdf source, so may works for you.

  • pelinalpppelinalpp Member ✭✭

    Thank you for reply. I saw it but I need to preview for each type file. I guess Syncfusion has pdf and word viewer but it isn't enough for me.

Sign In or Register to comment.