public async void EncryptFileToNewFile() { //eg. encrypt a file and generate new encrypted file //XamEncDec.EncryptFileAsNewFile(<true/false to delete source file>, //<True=local directory,False=use custom path>, <set string for custom path>, //<new/existing folder name>, <file name to be encrypted>, <password for encryption>, //<new file name for encrypted file>); bool isFileEncrypted = false; if (Device.RuntimePlatform == Device.Android) { isFileEncrypted = await XamEncDec.EncryptFileAsNewFile(false, false, CrossXamarinFileEncryptorDecryptor.Current.GetAndroidExternalStoragePath(), "folderName1", "MARBLES.JPG", "myPassword", "MARBLES_ENCRYPTED.JPG"); } }
private async void EncryptFileToNewFile_Clicked(object sender, EventArgs e) { if (ent_filetofile_filename.Text != "" && ent_filetofile_filename.Text != null) { var file = await CrossFilePicker.Current.PickFile(); if (file != null) { await Navigation.PushModalAsync(popup); await Task.Delay(5000); StringBuilder stb = new StringBuilder(file.FilePath); int postIndex = IndexOf(stb, file.FileName, 0, true); string folderPath = stb.Remove(postIndex, file.FilePath.Length - postIndex).ToString(); //convert android content Uri into physical path, normally happens in Android emulator folderPath = ConvertAndroidContentUriPath(folderPath); bool isFileEncrypted = await XamEncDec.EncryptFileAsNewFile(false, false, folderPath, "", file.FileName, "myPassword", ent_filetofile_filename.Text); if (isFileEncrypted) { await DisplayAlert("Encrypt", "File successfully encrypted", "OK"); } else { await DisplayAlert("Error", "Encryption failed", "OK"); } file.Dispose(); await Navigation.PopModalAsync(); } } else { await DisplayAlert("Error", "Please set the filename", "OK"); } }