![](/img/trans.png)
[英]Download Blob file into Memory Stream from Azure using C#
[英]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.