private async Task <int> UploadFileStreamFromTempFolder(string fileName, long postId) { var(fileByte, filePath, orignalFileName) = _fileStreamService.GetTempFile(fileName, CommonConstant.FILE_TEMP_FOLDER_POST); if (fileByte == null) { return(0); } string base64Str = Convert.ToBase64String(fileByte); FileDataUploadRequestModel fileUpdateModel = new FileDataUploadRequestModel(); fileUpdateModel.FileTypeFid = (int)FileTypeEnum.Image; fileUpdateModel.FolderId = Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(postId.ToString())); fileUpdateModel.DomainId = CommonConstant.FILE_STREAM_CMS_DOMAIN; fileUpdateModel.FileName = _aQFileProvider.GetFileNameWithoutExtension(orignalFileName); fileUpdateModel.FileExtention = _aQFileProvider.GetFileExtension(orignalFileName); fileUpdateModel.FileData = base64Str; var res = await _fileStreamService.UploadFileData(fileUpdateModel); if (res != null) { int fileId = res.ResponseData.FileId; if (fileId > 0) { _fileStreamService.DeleteFileTemp(fileName, CommonConstant.FILE_TEMP_FOLDER_POST); } return(fileId); } return(0); }
public async Task <IActionResult> UploadImage(IFormFile file) { byte[] CoverImageBytes = null; string s = string.Empty; BinaryReader reader = new BinaryReader(file.OpenReadStream()); CoverImageBytes = reader.ReadBytes((int)file.Length); s = Convert.ToBase64String(CoverImageBytes); FileDataUploadRequestModel fileUpdateModel = new FileDataUploadRequestModel(); fileUpdateModel.FileTypeFid = (int)FileTypeEnum.Image; fileUpdateModel.FolderId = CommonConstant.POST_IMAGE_FOLDER; fileUpdateModel.DomainId = CommonConstant.FILE_STREAM_CMS_DOMAIN; fileUpdateModel.FileName = file.FileName.Split('.')[0]; fileUpdateModel.FileExtention = '.' + file.FileName.Split('.')[1]; fileUpdateModel.FileData = s; var res = await _fileStreamService.UploadFileData(fileUpdateModel); if (res != null) { var fileId = res.ResponseData.FileId; var url = await _fileStreamService.GetFileById(fileId, ThumbRatioEnum.full); var result = new Tuple <int, string>(fileId, url); return(Ok(result)); } return(BadRequest()); }
public async Task <ViewResult> UploadFileData(FileDataUploadRequestModel fileDataUploadRequestModel) { try { FileStream stream; bool uploadSucceed; if (fileDataUploadRequestModel.FileAsHttpPostedFileBase?.ContentLength > 0) { var path = Path.Combine(Server.MapPath("~/Content/images/"), fileDataUploadRequestModel.FileAsHttpPostedFileBase.FileName); fileDataUploadRequestModel.FilePath = path; fileDataUploadRequestModel.FileAsHttpPostedFileBase.SaveAs(path); uploadSucceed = await _homeService.Upload(fileDataUploadRequestModel); if (uploadSucceed) { ModelState.AddModelError(string.Empty, "Uploaded Successfully"); } } else { throw new Exception("File are empty"); } } catch (Exception ex) { Console.WriteLine($"Exception was thrown: {ex}"); ModelState.AddModelError(string.Empty, ex.Message); return(View()); } return(View()); }
public string ExtractMessageFromVideo(FileDataUploadRequestModel fileData) { AesAlgo aesAlgo = new AesAlgo(); //byte[] video = new byte[fileData.FileAsHttpPostedFileBase.ContentLength]; //fileData.FileAsHttpPostedFileBase.InputStream.Read(video, 0, video.Length); byte[] video = fileData.FileAsByteArray; byte[] cypherData = null; byte[] key = null; byte[] iv = null; string decryptedMessage = null; switch (fileData.HidingMethod) { case HidingMethod.Lsb: if (fileData.FileName.EndsWith(".avi")) { cypherData = _lsbVideo.SeekAvi(video); key = _lsbVideo.ExtractKeyAvi(video); iv = _lsbVideo.ExtractIvAvi(video); } else { cypherData = _lsbVideo.SeekMov(video); key = _lsbVideo.ExtractKeyMov(video); iv = _lsbVideo.ExtractIvMov(video); } break; case HidingMethod.MetaData: if (fileData.FileName.EndsWith(".avi")) { cypherData = _metaDataVideo.SeekAvi(video); key = _metaDataVideo.ExtractKeyAvi(video); iv = _metaDataVideo.ExtractIvAvi(video); } else { cypherData = _metaDataVideo.SeekMov(video); key = _metaDataVideo.ExtractKeyMov(video); iv = _metaDataVideo.ExtractIvMov(video); } break; } switch (fileData.EncryptionMethod) { case EncryptionMethod.Aes: decryptedMessage = Decrypt_Aes(cypherData, key, iv); break; case EncryptionMethod.Serpent: decryptedMessage = Decrypt_Serpent(cypherData, key); break; } return(decryptedMessage); }
public string ExtractMessageFromAudio(FileDataUploadRequestModel fileData) { AesAlgo aesAlgo = new AesAlgo(); byte[] audio = fileData.FileAsByteArray; byte[] cypherData = null; byte[] key = null; byte[] iv = null; string decryptedMessage = null; switch (fileData.HidingMethod) { case HidingMethod.Lsb: if (fileData.FileName.EndsWith(".wav")) { cypherData = _lsbAudio.SeekWave(audio); key = _lsbAudio.ExtractKeyWave(audio); iv = _lsbAudio.ExtractIvWave(audio); } else { cypherData = _lsbAudio.SeekMp3(audio); key = _lsbAudio.ExtractKeyMp3(audio); iv = _lsbAudio.ExtractIvMp3(audio); } break; case HidingMethod.MetaData: if (fileData.FileName.EndsWith(".wav")) { cypherData = _metaDataAudio.SeekWave(audio); key = _metaDataAudio.ExtractKeyWave(audio); iv = _metaDataAudio.ExtractIvWave(audio); } else { cypherData = _metaDataAudio.SeekMp3(audio); key = _metaDataAudio.ExtractKeyMp3(audio); iv = _metaDataAudio.ExtractIvMp3(audio); } break; } switch (fileData.EncryptionMethod) { case EncryptionMethod.Aes: decryptedMessage = Decrypt_Aes(cypherData, key, iv); break; case EncryptionMethod.Serpent: //decryptedMessage = Decrypt_Des(cypherData, key, iv); decryptedMessage = Decrypt_Serpent(cypherData, key); break; } return(decryptedMessage); }
public string ExtractMessageFromExe(FileDataUploadRequestModel fileData) { AesAlgo aesAlgo = new AesAlgo(); // var ms = new MemoryStream(fileData.File); byte[] Exe = fileData.FileAsByteArray; byte[] cypherData = null; byte[] key = null; byte[] iv = null; string decryptedMessage = null; switch (fileData.HidingMethod) { case HidingMethod.Lsb: if (fileData.FileName.EndsWith(".exe")) { cypherData = _lsbExe.SeekPE(Exe); key = _lsbExe.ExtractKeyPE(Exe); iv = _lsbExe.ExtractIvPE(Exe); } break; case HidingMethod.MetaData: if (fileData.FileName.EndsWith(".exe")) { cypherData = _metaDataExe.SeekPE(Exe); key = _metaDataExe.ExtractKeyPE(Exe); iv = _metaDataExe.ExtractIvPE(Exe); } else if (fileData.FileName.EndsWith(".bat")) { cypherData = _metaDataExe.SeekBatch(Exe); key = _metaDataExe.ExtractKeyBatch(Exe); iv = _metaDataExe.ExtractIvBatch(Exe); } break; } switch (fileData.EncryptionMethod) { case EncryptionMethod.Aes: decryptedMessage = Decrypt_Aes(cypherData, key, iv); break; case EncryptionMethod.Serpent: decryptedMessage = Decrypt_Serpent(cypherData, key); break; } return(decryptedMessage); }
public static FileDataUploadRequestModel Convert(this FileDataUploadResponseModel data) { var obj = new FileDataUploadRequestModel { FileAsByteArray = data.File, Id = data.Id, PermittedUsers = data.PermittedUsers, //SecretMessage = data.SecretMessage, EncryptionMethod = data.EncryptionMethod, HidingMethod = data.HidingMethod, FileType = data.FileType, FileName = data.FileName }; return(obj); }
public byte[] EncryptAndHideInAudio(FileDataUploadRequestModel fileData) { byte[] byteAudio = File.ReadAllBytes(fileData.FilePath); byte[] encrypteMessage = null; string encryptedBinary = null; switch (fileData.EncryptionMethod) { case EncryptionMethod.Aes: encrypteMessage = Encrypt_Aes(fileData.SecretMessage); break; case EncryptionMethod.Serpent: encrypteMessage = Encrypt_Serpent(fileData.SecretMessage); break; } switch (fileData.HidingMethod) { case HidingMethod.Lsb: encryptedBinary = _decoder.EncryptedByteArrayToBinary(encrypteMessage); if (fileData.FileExtension == ".wav") { _lsbAudio.HideWave(byteAudio, encryptedBinary); } else if (fileData.FileExtension == ".mp3") { byteAudio = _lsbAudio.GenerateFramesMp3(byteAudio); _lsbAudio.HideMp3(byteAudio, encryptedBinary); } break; case HidingMethod.MetaData: if (fileData.FileExtension == ".wav") { _metaDataAudio.HideWave(byteAudio, encrypteMessage); } else if (fileData.FileExtension == ".mp3") { byteAudio = _metaDataAudio.GenerateFramesMp3(byteAudio); _metaDataAudio.HideMp3(byteAudio, encrypteMessage); } break; } return(byteAudio); }
public static FileDataUploadResponseModel Convert(this FileDataUploadRequestModel data) { var obj = new FileDataUploadResponseModel { File = File.ReadAllBytes(data.FilePath), Id = data.Id, FileName = data.FileAsHttpPostedFileBase.FileName, PermittedUsers = data.PermittedUsers, //SecretMessage = data.SecretMessage, EncryptionMethod = data.EncryptionMethod, HidingMethod = data.HidingMethod, FileExtension = Path.GetExtension(data.FilePath), SharingUser = data.SharingUser }; return(obj); }
public byte[] EncryptAndHideInVideo(FileDataUploadRequestModel fileData) { byte[] byteVideo = File.ReadAllBytes(fileData.FilePath); byte[] encryptedData = null; string encryptedBinary = null; switch (fileData.EncryptionMethod) { case EncryptionMethod.Aes: encryptedData = Encrypt_Aes(fileData.SecretMessage); break; case EncryptionMethod.Serpent: //encryptedData = Encrypt_Des(fileData.SecretMessage); encryptedData = Encrypt_Serpent(fileData.SecretMessage); break; } switch (fileData.HidingMethod) { case HidingMethod.Lsb: encryptedBinary = _decoder.EncryptedByteArrayToBinary(encryptedData); if (fileData.FileExtension == ".avi") { _lsbVideo.HideAvi(byteVideo, encryptedBinary); } else if (fileData.FileExtension == ".mov") { _lsbVideo.HideMov(byteVideo, encryptedBinary); } break; case HidingMethod.MetaData: if (fileData.FileExtension == ".avi") { _metaDataVideo.hideAvi(byteVideo, encryptedData); } else if (fileData.FileExtension == ".mov") { _metaDataVideo.HideMov(byteVideo, encryptedData); } break; } return(byteVideo); }
public async Task <BaseResponse <FileUploadResponseModel> > UploadFileData(FileDataUploadRequestModel model) { try { var req = new BaseRequest <FileDataUploadRequestModel>(model); var res = await _aPIExcute.PostData <FileUploadResponseModel, FileDataUploadRequestModel>($"{_baseFileStreamAPIUrl}{_adminPortalApiUrl.FileStreamAPI.FileData}", HttpMethodEnum.POST, req, _basicAPIToken); if (res.IsSuccessStatusCode) { return(res); } return(null); } catch (Exception ex) { return(BaseResponse <FileUploadResponseModel> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace)); } }
public async Task <bool> Upload(FileDataUploadRequestModel fileDataUploadRequestModel) { var auth = new FirebaseAuthProvider(new FirebaseConfig(ApiKey)); Client = new FirebaseClient(Config); fileDataUploadRequestModel.SharingUser = HttpContext.Current.GetOwinContext().Authentication.User.Claims.First().Value; fileDataUploadRequestModel.FileExtension = Path.GetExtension(fileDataUploadRequestModel.FilePath); var fileDataUploadResponseModel = fileDataUploadRequestModel.Convert(); SetFileType(fileDataUploadResponseModel); Console.WriteLine(fileDataUploadRequestModel.HidingMethod); Console.WriteLine(fileDataUploadRequestModel.EncryptionMethod); switch (fileDataUploadResponseModel.FileType) { case FileType.Image: fileDataUploadResponseModel.File = EncryptAndHideInPicture(fileDataUploadRequestModel); break; case FileType.Video: fileDataUploadResponseModel.File = EncryptAndHideInVideo(fileDataUploadRequestModel); break; case FileType.Audio: fileDataUploadResponseModel.File = EncryptAndHideInAudio(fileDataUploadRequestModel); break; case FileType.Executable: fileDataUploadResponseModel.File = EncryptAndHideInBatchFile(fileDataUploadRequestModel); break; } var response = await Client.PushAsync("Files/", fileDataUploadResponseModel); fileDataUploadResponseModel.Id = response.Result.name; var setResult = await Client.SetAsync("Files/" + fileDataUploadResponseModel.Id, fileDataUploadResponseModel); return(setResult.StatusCode == HttpStatusCode.OK); }
public byte[] EncryptAndHideInBatchFile(FileDataUploadRequestModel fileData) { byte[] file = File.ReadAllBytes(fileData.FilePath); byte[] encrypteMessage = null; string encryptedBinary = null; switch (fileData.EncryptionMethod) { case EncryptionMethod.Aes: encrypteMessage = Encrypt_Aes(fileData.SecretMessage); break; case EncryptionMethod.Serpent: encrypteMessage = Encrypt_Serpent(fileData.SecretMessage); break; } switch (fileData.HidingMethod) { case HidingMethod.Lsb: encryptedBinary = _decoder.EncryptedByteArrayToBinary(encrypteMessage); if (fileData.FileExtension == ".exe") { _lsbExe.HidePE(file, encryptedBinary); } break; case HidingMethod.MetaData: if (fileData.FileExtension == ".exe") { _metaDataExe.HideMetaDataPE(file, encrypteMessage); } else if (fileData.FileExtension == ".bat") { file = _metaDataExe.HideBatch(file, encrypteMessage); } break; } return(file); }
/// **************************************************************************** /// Decryption and Seeking handlers by File type /// **************************************************************************** public string ExtractMessage(FileDataUploadRequestModel fileData) { if (fileData.FileType == FileType.Video) { return(ExtractMessageFromVideo(fileData)); } if (fileData.FileType == FileType.Image) { return(ExtractMessageFromPicture(fileData)); } if (fileData.FileType == FileType.Audio) { return(ExtractMessageFromAudio(fileData)); } if (fileData.FileType == FileType.Executable) { return(ExtractMessageFromExe(fileData)); } return("No Suitable file type was uploaded"); }
/// **************************************************************************** /// Encryption and hiding handlers by File type /// **************************************************************************** public byte[] EncryptAndHideInPicture(FileDataUploadRequestModel fileData) { Bitmap bmp = (Bitmap)Image.FromStream(fileData.FileAsHttpPostedFileBase.InputStream, true, false); byte[] encryptedData = null; string encryptedBinary = null; switch (fileData.EncryptionMethod) { case EncryptionMethod.Aes: encryptedData = Encrypt_Aes(fileData.SecretMessage); break; case EncryptionMethod.Serpent: //encryptedData = Encrypt_Des(fileData.SecretMessage); ////***************** encryptedData = Encrypt_Serpent(fileData.SecretMessage); break; } switch (fileData.HidingMethod) { case HidingMethod.Lsb: encryptedBinary = _decoder.EncryptedByteArrayToBinary(encryptedData); _lsbPicture.HideBitmap(bmp, encryptedBinary); break; case HidingMethod.MetaData: return(_metaDataPicture.HideJpeg(File.ReadAllBytes(fileData.FilePath), encryptedData)); //(File.ReadAllBytes(fileData.FilePath) = byte [] of jpeg) break; } using (var stream = new MemoryStream()) { bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png); return(stream.ToArray()); } }
public string ExtractMessageFromPicture(FileDataUploadRequestModel fileData) { AesAlgo aesAlgo = new AesAlgo(); var ms = new MemoryStream(fileData.FileAsByteArray); var bmp = new Bitmap(ms); byte[] cypherData = null; byte[] key = null; byte[] iv = null; string decryptedMessage = null; switch (fileData.HidingMethod) { case HidingMethod.Lsb: cypherData = _lsbPicture.SeekBitmap(bmp); key = _lsbPicture.ExtractKeyBitmap(bmp); iv = _lsbPicture.ExtractIvBitmap(bmp); break; case HidingMethod.MetaData: cypherData = _metaDataPicture.SeekJpeg(fileData.FileAsByteArray); key = _metaDataPicture.ExtractKeyJpeg(fileData.FileAsByteArray); iv = _metaDataPicture.ExtractIvJpeg(fileData.FileAsByteArray); break; } switch (fileData.EncryptionMethod) { case EncryptionMethod.Aes: decryptedMessage = Decrypt_Aes(cypherData, key, iv); break; case EncryptionMethod.Serpent: decryptedMessage = Decrypt_Serpent(cypherData, key); break; } return(decryptedMessage); }
public ActionResult ShowSecretMessage(FileDataUploadRequestModel fileData) { return(Content(fileData.SecretMessage)); }