简体   繁体   English

无法使用 SSIS 脚本任务中的 C# 脚本将 PGP 加密文件从 Azure Blob 存储解密为 Stream

[英]Unable to decrypt PGP encrypted file into Stream from Azure Blob storage using C# scripting within script task of SSIS

I am trying to read the PGP encrypted file from Azure Blob Storage using SSIS package - Script Task- C# code into Stream, decrypt the file data into string and load to Azure SQL MI server.我正在尝试使用 SSIS package - 脚本任务 - C# 代码从 Azure Blob 存储读取 PGP 加密文件到 Stream,将文件数据解密为字符串并加载到 Azure2861529 But I am not able to decrypt the file from Azure blob storage.但我无法从 Azure blob 存储中解密文件。 When if I am reading the PGP encrypted file from Azure blob storage and downloading to the local folder, then from local folder I am able to decrypt the file and store the decrypted data into string.如果我从 Azure blob 存储读取 PGP 加密文件并下载到本地文件夹,那么我可以从本地文件夹解密文件并将解密数据存储到字符串中。

Below the Main program - ScriptMain.cs在主程序下方 - ScriptMain.cs

  public void Main()
            {
                try
                {
                    #region variables
                     string azureBlob = Dts.Variables["User::vAzureBlobContainer"].Value.ToString();
                    string azureStorageAccessKey = Dts.Variables["User::vAzureStorageAccessKey"].Value.ToString();
                    string azureStorageAccount = Dts.Variables["User::vAzureStorageAccount"].Value.ToString();
    
                  
                    StorageCredentials credentials = new StorageCredentials(azureStorageAccount, azureStorageAccessKey);
    
                    checkPoints = "1. Storage Login";
                    string inputFileName = @"FileInput.csv.pgp";
                    string keyFileName = @"C:\\PrivateKey\\keyfile.asc";
                    string passwd = @"z6yrFkE2NwzX";
                    
                    char[] password1 = passwd.ToCharArray();
                    string output;
                    output= PGPDecrypt.Program.DecryptFile(inputFileName, keyFileName, password1, credentials, azureBlob);
    
                 string[] lines = output.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
    
                       int count = 0;
    
                       foreach(string line in lines)
                       {
                           count++;
    
                       }
    
                       int cnt;
                       cnt = count;
                }
                catch (Exception ex)
                {
                    Dts.Events.FireError(0, "ERROR", checkPoints + ",\n" + ex.Message, null, 0);
                    Dts.TaskResult = (int)ScriptResults.Failure;
                    //throw;
                }
            }

Note: All required libraries added to ScriptMain.cs注意:所有必需的库都已添加到 ScriptMain.cs

Decrypt.cs解密.cs

As mentioned by the OP that the issue has been resolved.正如 OP 所提到的,该问题已得到解决。

(Posting the findings as an answer so that if someone faced the similar issue in future, he would get the solution on this thread. This will be helpful for other community contributors.) (将调查结果作为答案发布,以便将来如果有人遇到类似问题,他将在此线程上获得解决方案。这将对其他社区贡献者有所帮助。)

The issue has been resolved after setting the stream position to 0 right after writing in stream (mystream.position = 0) .在写入 stream (mystream.position = 0)后立即将 stream position 设置为0后问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 下载 Blob 文件到 Memory Stream 从 Azure 使用 ZD7EFA19FBE74D3972FDZ5ADB6D - Download Blob file into Memory Stream from Azure using C# 如何使用 C# 中的 Azure.Storage.Blobs 以 ByteArray 格式从 Azure 存储 blob 中获取文件 - How to get file from Azure storage blob in a ByteArray format using Azure.Storage.Blobs in C# 如何使用 C# 将文件上传到 Azure Blob 存储? - How to upload file into Azure Blob Storage using C#? 无法使用 SAS 从 Azure Blob 存储检索文件 - Unable to retrieve file from Azure Blob Storage using SAS 使用 C# 解密和解压缩 Azure Blob 存储中的数据 - Decrypting and Decompressing Data from Azure Blob Storage using C# 使用版本 12.x Azure 存储库使用密钥保管库从 Azure Blob 存储中解密 Blob - Decrypt a blob from Azure blob storage with key vault using version 12.x Azure storage libraries 如何使用 c# 从 azure blob 存储中检索 xml 文件 - how to retrieve an xml file from azure blob storage using c# 使用 c# 将文件从 azure 文件共享移动到 blob 存储 - Move files from azure file shares into blob storage by using c# C#没有从Azure blob存储中检索blob - C# not retrieving blob from Azure blob storage C#Azure将文件上载到“文件存储服务” - 而不是Blob存储 - C# Azure Upload Files to “File Storage Service” - not Blob Storage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM