I'm trying to generate a signature file using my private key for a source file. the command works fine when I run it in command prompt. But when I try to do the same through the code, signature is not generating.
This is the code I'm using
static void CreateOpenSSLSignature(string sourceFile, string sslPrivateKeyPath)
{
// Get required values
if (File.Exists(signatureFilepath))
{
File.Delete(signatureFilepath);
}
var sigFile = File.Create(signatureFilepath);
sigFile.Close();
try
{
// Start decryption process
Process myProcess = new Process();
myProcess.StartInfo.FileName = openSSLPath + "\\bin\\openssl.exe";
myProcess.StartInfo.WorkingDirectory = openSSLPath + "/bin/";
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.StartInfo.ErrorDialog = true;
string arg = dgst -sha1 -sign sslPrivateKeyPath -binary sourcefilepath | openssl enc -base64
>> signaturefilepath
myProcess.StartInfo.Arguments = arg.ToString();
myProcess.Start();
myProcess.WaitForExit(10000); }
catch (Exception ex)
{
}
}
check this way. "set your openssl path":