You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am trying to decrypt a Stream using an Azure function app in which the function is http triggered and the data to be decrypted is passed into req.body.
The passphrase and key are stored in a vault, I have verified that they work using gpg4win, and that the app can access them and they print out correctly.
Can you help me figure out why I am seeing the error "Secret Key for message cannot be found" when the key, passphrase, and data are being passed correctly?
using System.IO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using PgpCore;
using System.Threading.Tasks;
using Microsoft.Azure.KeyVault.Models;
using System.Net.Http;
using Microsoft.Azure.Services.AppAuthentication;
using Microsoft.Azure.KeyVault;
using System;
using System.Text;
using System.Collections.Concurrent;
using Microsoft.Extensions.Logging;
namespace AzureFunctionsPGPDecrypt
{
public static class PGPDecrypt
{
private static readonly HttpClient client = new HttpClient();
private static ConcurrentDictionary<string, string> secrects = new ConcurrentDictionary<string, string>();
[FunctionName(nameof(PGPDecrypt))]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
HttpRequest req, ILogger log)
{
log.LogInformation($"C# HTTP trigger function {nameof(PGPDecrypt)} processed a request.");
string privateKey = Environment.GetEnvironmentVariable("secretkey", EnvironmentVariableTarget.Process);
string passPhrase= Environment.GetEnvironmentVariable("secretphrase", EnvironmentVariableTarget.Process);
log.LogInformation($"SecretKey: {privateKey}");
log.LogInformation($"SecretPassPhrase: {passPhrase}");
if (privateKey == null)
{
return new BadRequestObjectResult("Please pass a private key secret identifier on the query string");
}
Stream outputStream = new MemoryStream();
Stream privateKeyStream = GenerateStreamFromString(privateKey);
var length = privateKeyStream.Length;
var length2 = req.Body.Length;
log.LogInformation($"Length private key stream: {length}");
log.LogInformation($"Length body: {length2}");
//verifying that the streams were not empty
using (PGP pgp = new PGP())
{
using (Stream inputStream = req.Body)
using(outputStream)
using (privateKeyStream)
{
pgp.DecryptStreamAsync(inputStream, outputStream, privateKeyStream, passPhrase);
return new OkObjectResult(outputStream);
}
}
}
private static Stream GenerateStreamFromString(string s)
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
}
}
The text was updated successfully, but these errors were encountered:
Hi, I am trying to decrypt a Stream using an Azure function app in which the function is http triggered and the data to be decrypted is passed into req.body.
The passphrase and key are stored in a vault, I have verified that they work using gpg4win, and that the app can access them and they print out correctly.
Can you help me figure out why I am seeing the error "Secret Key for message cannot be found" when the key, passphrase, and data are being passed correctly?
using System.IO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using PgpCore;
using System.Threading.Tasks;
using Microsoft.Azure.KeyVault.Models;
using System.Net.Http;
using Microsoft.Azure.Services.AppAuthentication;
using Microsoft.Azure.KeyVault;
using System;
using System.Text;
using System.Collections.Concurrent;
using Microsoft.Extensions.Logging;
namespace AzureFunctionsPGPDecrypt
{
public static class PGPDecrypt
{
private static readonly HttpClient client = new HttpClient();
private static ConcurrentDictionary<string, string> secrects = new ConcurrentDictionary<string, string>();
//verifying that the streams were not empty
}
The text was updated successfully, but these errors were encountered: