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(); } }
public void Dispose() { if (m_isDisposable) { FileData.Dispose(); m_isDisposable = false; } }
private void FromBMP(FileData file) { byte[] b; using (var memoryStream = new MemoryStream()) { file.GetStream().CopyTo(memoryStream); file.Dispose(); b = memoryStream.ToArray(); memoryStream.Close(); memoryStream.Dispose(); } Int16 offset = BitConverter.ToInt16(b.ToList().Skip(10).Take(4).ToArray(), 0); Int16 width = BitConverter.ToInt16(b.ToList().Skip(18).Take(4).ToArray(), 0); Int16 height = BitConverter.ToInt16(b.ToList().Skip(22).Take(4).ToArray(), 0); // // size check? // List <byte> lb = b.ToList().Skip(offset).ToList(); int bytesPerRow = (int)Math.Ceiling(width / 8d); int bytesToSkipEachRow = bytesPerRow % 4; if (bytesToSkipEachRow != 0) { bytesToSkipEachRow = 4 - bytesToSkipEachRow; } List <bool> final = new List <bool>(); List <byte> row; bool[] boolAray; List <bool> boolList; for (int i = 0; i < height; i++) { if (i == 129) { } row = lb.Take(bytesPerRow).ToList(); lb.RemoveRange(0, bytesPerRow + bytesToSkipEachRow); boolAray = new bool[width]; if (width % 8 != 0) { boolAray = new bool[(8 - width % 8) + width]; } BitArray bitArray = new BitArray(row.ToArray()); bitArray.CopyTo(boolAray, 0); boolList = boolAray.ToList(); for (int j = 0; j < row.Count; j++) { boolList.AddRange(boolList.Take(8).Reverse().ToList()); boolList.RemoveRange(0, 8); } boolList.Reverse(); if (width % 8 != 0) { boolList.RemoveRange(0, 8 - width % 8); } final.Reverse(); final.AddRange(boolList); final.Reverse(); } this.width = width; this.height = height; this.image = EncodeLargeBool(final.ToArray()); }
public void Delete()//doesnt delete actual file, only the memory reference { FileName = ""; FileData.Dispose(); }
SimpleImage FileToSimpleImage(FileData file) { byte[] b; using (var memoryStream = new MemoryStream()) { file.GetStream().CopyTo(memoryStream); file.Dispose(); b = memoryStream.ToArray(); memoryStream.Close(); memoryStream.Dispose(); } Int16 offset = BitConverter.ToInt16(b.ToList().Skip(10).Take(4).ToArray(), 0); Int16 width = BitConverter.ToInt16(b.ToList().Skip(18).Take(4).ToArray(), 0); Int16 height = BitConverter.ToInt16(b.ToList().Skip(22).Take(4).ToArray(), 0); if (width * height > 128 * 8) { return(null); } List <byte> lb = b.ToList().Skip(offset).ToList(); int bytesPerRow = (int)Math.Ceiling(width / 8d); int bytesToSkipEachRow = bytesPerRow % 4; if (bytesToSkipEachRow != 0) { bytesToSkipEachRow = 4 - bytesToSkipEachRow; } List <bool> final = new List <bool>(); BitArray bitArray; List <byte> row; bool[] boolAray; List <bool> boolList; for (int i = 0; i < height; i++) { row = lb.Take(bytesPerRow).ToList(); lb.RemoveRange(0, bytesPerRow + bytesToSkipEachRow); boolAray = new bool[width]; if (width % 8 != 0) { boolAray = new bool[(8 - width % 8) + width]; } bitArray = new BitArray(row.ToArray()); bitArray.CopyTo(boolAray, 0); if (width % 8 != 0) { boolList = boolAray.ToList(); boolList.RemoveRange(0, 8 - width % 8); } else { boolList = boolAray.ToList(); } final.AddRange(boolList); } bitArray = new BitArray(final.ToArray()); bitArray.Not(); SimpleImage simpleImage = new SimpleImage(width, height, bitArray); return(simpleImage); }