Ejemplo n.º 1
0
        private async void EncryptResFileToBase64String_Clicked(object sender, EventArgs e)
        {
            if (p_resfile1.SelectedIndex == -1)
            {
                await DisplayAlert("Error", "Please select resource file", "OK");
            }
            else
            {
                await Navigation.PushModalAsync(popup);

                await Task.Delay(5000);

                string encryptedStr = await XamEncDec.EncryptResourceFileAsBase64String(assembly, GetResourceValue(p_resfile1.SelectedIndex), "myPassword");

                if (encryptedStr != "")
                {
                    //edt_encrestostr.Text = encryptedStr;
                    Output outp = new Output();
                    outp.OutputStr = encryptedStr;
                    var OutputPage = new OutputText();
                    OutputPage.BindingContext = outp;
                    await Navigation.PushAsync(OutputPage);
                }
                else
                {
                    await DisplayAlert("Error", "Resource file failed to encrypted", "OK");
                }
                await Navigation.PopModalAsync();
            }
        }
Ejemplo n.º 2
0
        private async void EncryptFileToBase64String_Clicked(object sender, EventArgs e)
        {
            FileData 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);

                string encryptedStr = await XamEncDec.EncryptFileAsBase64String(false, false, folderPath, "", file.FileName, "myPassword");

                //edt_encfiletostr.Text = encryptedStr;
                file.Dispose();
                Output outp = new Output();
                outp.OutputStr = encryptedStr;
                var OutputPage = new OutputText();
                OutputPage.BindingContext = outp;
                await Navigation.PushAsync(OutputPage);

                await Navigation.PopModalAsync();
            }
        }
Ejemplo n.º 3
0
        public async void DecryptEncryptedString(string encryptedString)
        {
            //eg. decrypt encrypted Base64 string

            //XamEncDec.DecryptEncryptedStringAsBase64String(<encrypted string>, <password used for encryption>);
            var decryptedString = await XamEncDec.DecryptEncryptedStringAsString(encryptedString, "myPassword");
        }
Ejemplo n.º 4
0
        public async void EncryptResourceFileToBase64String(Assembly assembly, string resourceName, string password)
        {
            //eg. encrypt resource file and generate encrypted Base64 string

            //XamEncDec.EncryptResourceFileAsBase64String(<Assembly object>,
            //<Resource filename>, <password>);
            var encryptedString = await XamEncDec.EncryptResourceFileAsBase64String(assembly, "TestFileEncryptDecryptXamarin.Files.MARBLES.JPG", "myPassword");
        }
Ejemplo n.º 5
0
        public async void EncryptFileToBase64String()
        {
            //eg. encrypt a file and generate encrypted base64 string

            //XamEncDec.EncryptFileAsBase64String(<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>);
            var encryptedString = await XamEncDec.EncryptFileAsBase64String(false, true, "", "folderName2", "MARBLES.JPG", "myPassword");
        }
Ejemplo n.º 6
0
        public async void EncryptResourceFileToNewFile()
        {
            //eg. encrypt resource file and generate a new encrypted file

            //XamEncDec.EncryptResourceFileAsNewFile(<Assembly object>, <Resource filename>,
            //<True=local directory,False=use custom path>,<set string for custom path>,
            //<new/existing folder name>,<new filename>, <password>);
            var isFileEncrypted = await XamEncDec.EncryptResourceFileAsNewFile(assembly, "TestFileEncryptDecryptXamarin.Files.MARBLES.JPG", true, "", "folderName1", "MARBLES.JPG", "myPassword");
        }
Ejemplo n.º 7
0
        public async void DecryptEncryptedFileToNewFile()
        {
            //eg. decrypt encrypted file to a new file

            //XamEncDec.DecryptFileAsNewFile(<True=local directory,False=use custom path>,
            //<set string for custom path>, <folder name for output>, <encrypted filename>,
            //<password used for encryption>, <new filename for decrypted file>);
            var isFileDecrypted = await XamEncDec.DecryptFileAsNewFile(true, "", "folderName1", "MARBLES_ENCRYPTED.JPG", "myPassword", "MARBLES_DECRYPTED.JPG");
        }
Ejemplo n.º 8
0
        public async void DecryptEncryptedStringToNewFile(string encryptedString)
        {
            //eg. decrypt encrypted string to a new file

            //XamEncDec.DecryptEncryptedStringAsNewFile(<True=local directory,False=use custom path>,
            //<set string for custom path>, <folder name for output>, <encrypted Base64 string>,
            //<new filename for decrypted file>, <password used for encryption>);
            var isFileDecrypted = await XamEncDec.DecryptEncryptedStringAsNewFile(false, androidSDPath, "test7", encryptedString, "test1.jpg", "myPassword");
        }
Ejemplo n.º 9
0
        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 DecryptFileToNewFile_Clicked(object sender, EventArgs e)
        {
            if (ent_filetofile_filename.Text != "" && ent_filetofile_filename.Text != null)
            {
                var file = await CrossFilePicker.Current.PickFile();

                try
                {
                    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.DecryptFileAsNewFile(false, folderPath, "", file.FileName, "myPassword", ent_filetofile_filename.Text);

                        if (isFileEncrypted)
                        {
                            await DisplayAlert("Decrypt", "File successfully decrypted", "OK");
                        }
                        else
                        {
                            await DisplayAlert("Error", "Decryption failed", "OK");
                        }
                        file.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Error", "Decryption failed, file is not a valid encrypted file", "OK");
                }

                await Navigation.PopModalAsync();
            }
            else
            {
                await DisplayAlert("Error", "Please set the filename", "OK");
            }
        }
Ejemplo n.º 11
0
        private async void EncryptResFileToNewFile_Clicked(object sender, EventArgs e)
        {
            if (p_resfile2.SelectedIndex == -1)
            {
                await DisplayAlert("Error", "Please select resource file", "OK");
            }
            else
            {
                if (p_restofile.SelectedIndex == -1)
                {
                    await DisplayAlert("Error", "Please select path for generating encrpyted file", "OK");
                }
                else
                {
                    if (ent_restofile_filename.Text == "")
                    {
                        await DisplayAlert("Error", "Please set the filename", "OK");
                    }
                    else
                    {
                        await Navigation.PushModalAsync(popup);

                        await Task.Delay(5000);

                        bool isFileEncrypted = await XamEncDec.EncryptResourceFileAsNewFile(assembly,
                                                                                            GetResourceValue(p_resfile2.SelectedIndex),
                                                                                            UseLocalDirectory(p_restofile.SelectedIndex),
                                                                                            SetPath(p_restofile.SelectedIndex),
                                                                                            ent_restofile_foldername.Text, ent_restofile_filename.Text, "myPassword");

                        await Navigation.PopModalAsync();

                        if (isFileEncrypted)
                        {
                            await DisplayAlert("Encrypt", "File successfully encrypted", "OK");
                        }
                        else
                        {
                            await DisplayAlert("Error", "Encryption failed", "OK");
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public MainPage()
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);
            popup = new SharedPopup();
            //popup.IsLoading = true;
            //popup.ToggleTemp = true;
            //For using application directory - no direct access to user
            localPath = XamEncDec.GetLocalPath();

            //For using roaming directory - not all platform support this
            roamingPath = XamEncDec.GetRoamingPath();

            //For using external storage path in Android
            androidSDPath = "";
            if (Device.RuntimePlatform == Device.Android)
            {
                androidSDPath = CrossXamarinFileEncryptorDecryptor.Current.GetAndroidExternalStoragePath();
            }

            //For using shared document path - commonly for iOS
            documentPath = XamEncDec.GetDocumentsPath();

            //For using library path in iOS
            libraryPath = "";
            if (Device.RuntimePlatform == Device.iOS)
            {
                libraryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Library");
            }

            //Other paths that you can use, theres more if you google
            localAppDataPath  = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            commonAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
            commonDocPath     = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments);

            //getting the assembly to access resource files
            assembly = IntrospectionExtensions.GetTypeInfo(typeof(TestFileEncryptDecryptXamarin.App)).Assembly;
        }