private ObjParameter GetByteFile(MultipartFormDataStreamProvider provider, bool isGetFromBlob, string containerName, string blobName) { ObjParameter package = new ObjParameter(); string path = string.Empty; string StandardFilePath = Path.GetRandomFileName(); if (!isGetFromBlob) { // This illustrates how to get the file names. foreach (MultipartFileData file in provider.FileData) { path = file.LocalFileName; package.filename = file.Headers.ContentDisposition.FileName; } byte[] FileDecrypted = AESHelper.DescryptAES(System.IO.File.ReadAllBytes(path), Vault.Current.AESKeyBLOB); package.byteArr = FileDecrypted; } else { byte[] _ByteArray = BlobHelper.DownloadFileToArrayByte(Vault.Current.StorageConnectionString, containerName, blobName, Vault.Current.AESKeyBLOB); package.byteArr = _ByteArray; package.filename = blobName; } return(package); }
DownloadConversionFilesResult DownloadConversionFiles(ConversionRequest request, string storageConnString, string decryptKey) { if (string.IsNullOrEmpty(decryptKey)) { var msg = "AESKEY to encrypt/decrypt file is required."; return(DownloadConversionFilesResult.FailFast(msg)); } try { var primaryFileContent = BlobHelper.DownloadFileToArrayByte(storageConnString, request.containerName, request.blobHeaderName, decryptKey); if (primaryFileContent == null) { var msg = $"Can't find the content of the BLOB file [{request.blobHeaderName}]."; DownloadConversionFilesResult.FailFast(msg); } byte[] remittanceFileContent = null; if (!string.IsNullOrEmpty(request.blobDetailName)) { remittanceFileContent = BlobHelper.DownloadFileToArrayByte(storageConnString, request.containerName, request.blobDetailName, decryptKey); } return(DownloadConversionFilesResult.Successful(primaryFileContent, remittanceFileContent)); } catch (ApplicationException ex) { _logger.Error(ex.ToString()); return(DownloadConversionFilesResult.FailFast(ex.Message)); } }
private byte[] GetByteFile(IFormFile file, bool isGetFromBlob, string containerName, string blobName) { var decryptKey = _configuration["AESKeyBLOB"]; if (isGetFromBlob) { var storageAccountNameShared = _configuration["StorageAccountNameShared"]; var storageAccountKeyShared = _configuration["StorageAccountKeyShared"]; var aESSecretKey = _configuration["AESSecretKey"]; var storageSharedConnectionString = $"DefaultEndpointsProtocol=https;AccountName={storageAccountNameShared};AccountKey={AESHelper.DescryptAES(storageAccountKeyShared, aESSecretKey)}"; return(BlobHelper.DownloadFileToArrayByte(storageSharedConnectionString, containerName, blobName, decryptKey)); } Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); byte[] fileContent = null; using (var ms = new MemoryStream()) { file.CopyTo(ms); fileContent = ms.ToArray(); } //Issue: ko decrypt đc, input file ko phải complete block return(AESHelper.DescryptAES(fileContent, decryptKey)); //return fileContent; }
private byte[] GetByteFile(IFormFile fileData, bool isGetFromBlob, string containerName, string blobName) { var decryptKey = AzureKeyVaultProvider.AESKeyBLOB; // tại sao bên đây có case này còn bên payment thì default là down luon? if (isGetFromBlob) { //Non Vault var storageConnectionString = AzureKeyVaultProvider.StorageConnectionString; return(BlobHelper.DownloadFileToArrayByte(storageConnectionString, containerName, blobName, decryptKey)); } // register to read content of excel file Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); byte[] fileContent = null; using (var ms = new MemoryStream()) { fileData.CopyTo(ms); fileContent = ms.ToArray(); } return(AESHelper.DecryptAES(fileContent, decryptKey)); }
public MessageResponse convert(ConversionRequest reqValue) { LOGGER.Info("Conversion processing..."); if (reqValue == null || string.IsNullOrEmpty(reqValue.blobHeaderName) || string.IsNullOrEmpty(reqValue.blobOutputName) || string.IsNullOrEmpty(reqValue.containerName)) { return(MessageResponse.info("[blobHeaderName, blobOutputName, containerName] are required.")); } string BlobContainer = reqValue.containerName.Trim(); string BlobInputName = reqValue.blobHeaderName.Trim(); string BlobOutputName = reqValue.blobOutputName.Trim(); string AESKey = Vault.Current.AESKeyBLOB; string storageConnectionString = Vault.Current.StorageConnectionString; //validate parameter if (string.IsNullOrEmpty(BlobContainer)) { return(MessageResponse.info("Blob container is required.")); } if (string.IsNullOrEmpty(BlobInputName)) { return(MessageResponse.info("Blob file input is required.")); } if (string.IsNullOrEmpty(BlobOutputName)) { return(MessageResponse.info("Blob file output is required.")); } if (string.IsNullOrEmpty(AESKey)) { return(MessageResponse.info("AESKEY to encrypt/decrypt file is required.")); } try { // Retrieve reference to a previously created container. CloudBlobContainer blobContainer = BlobHelper.GetCloudBlobContainer(storageConnectionString, BlobContainer); Task <bool> IsExitBlobContainer = blobContainer.ExistsAsync(); if (blobContainer == null || !IsExitBlobContainer.Result) { return(MessageResponse.info(string.Format("Can't find the BLOB container [{0}].", BlobContainer))); } // Retrieve reference to a blob named "myblob". CloudBlockBlob blockBlobInput = blobContainer.GetBlockBlobReference(BlobInputName); Task <bool> IsExitblockBlobInput = blockBlobInput.ExistsAsync(); if (blockBlobInput == null || !IsExitblockBlobInput.Result) { return(MessageResponse.info(string.Format("Can't find the BLOB file [{0}].", BlobInputName))); } //download file byte[] fileInput = BlobHelper.DownloadFileToArrayByte(blockBlobInput, AESKey); if (fileInput == null) { return(MessageResponse.info(string.Format("Can't find the content of the BLOB file [{0}].", BlobInputName))); } //do conversion StringBuilder sbStandardFile = this.doConvert(fileInput); //no error: write the file standard if (this.ListErrorVendor == null || this.ListErrorVendor.Count == 0) { //upload the file standard file to azure BlobHelper.UploadFile(blobContainer, BlobOutputName, sbStandardFile, AESKey); //return the blob output name of file saved //LOGGER.Info(string.Format("File [{0}] converted to the file [{1}] and saved successfully in the BLOB container [{2}]", BlobInputName, BlobOutputName, BlobContainer)); return(MessageResponse.ok(reqValue.blobOutputName)); } //report errors if have if (this.ListErrors == null) { this.ListErrors = new List <string>(); } if (this.ListErrorVendor.Count > 0) { this.ListErrors.AddRange(this.ListErrorVendor); } return(MessageResponse.error(this.ListErrors)); } catch (Exception ex) { LOGGER.Error(ex); throw; } }