[英]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.