无法使用SSIS脚本任务中的C#脚本将PGP加密的文件从Azure Blob存储中加密到流中
我正在尝试使用SSIS软件包 - 脚本任务-C#代码从Azure Blob存储中读取PGP加密文件,将文件数据解密到字符串中,然后加载到Azure SQL Mi Server。但是我无法从Azure Blob存储中解密文件。如果我正在从Azure Blob存储中读取PGP加密文件并下载到本地文件夹中,则可以从本地文件夹中解密文件并将解密的数据存储到字符串中。
在主要程序下方-criptmain.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
decrypt.cs
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. But I am not able to decrypt the file from Azure blob storage. 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.
Below the Main program - 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
Decrypt.cs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如OP提到的那样,该问题已经解决。
(将调查结果发布为答案,以便如果某人将来遇到类似问题,他将在此线程上找到解决方案。这将对其他社区贡献者有所帮助。)
在将流立场设置为
0 在流中写入
(mystream.position = 0)
之后。As mentioned by the OP that the issue has been resolved.
(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)
.