簡體   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

我正在嘗試使用 SSIS package - 腳本任務 - C# 代碼從 Azure Blob 存儲讀取 PGP 加密文件到 Stream,將文件數據解密為字符串並加載到 Azure2861529 但我無法從 Azure blob 存儲中解密文件。 如果我從 Azure blob 存儲讀取 PGP 加密文件並下載到本地文件夾,那么我可以從本地文件夾解密文件並將解密數據存儲到字符串中。

在主程序下方 - 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;
                }
            }

注意:所有必需的庫都已添加到 ScriptMain.cs

解密.cs

正如 OP 所提到的,該問題已得到解決。

(將調查結果作為答案發布,以便將來如果有人遇到類似問題,他將在此線程上獲得解決方案。這將對其他社區貢獻者有所幫助。)

在寫入 stream (mystream.position = 0)后立即將 stream position 設置為0后問題已解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM