I need to pass a string variable to a popen command that I made for decripting a piece of encrypted data. The code segment I need to use is:
char a[]="Encrypted data";
popen("openssl aes-256-cbc -d -a -salt <a-which is the data i have to pass here>","r");
What should I do to pass this variable into the command. I tried with:
popen("openssl aes-256-cbc -d -a -salt %s",a,"r");
But on compiling showed error that popen is passed too many arguments. Please help. Thanks in advance. Operating Platform: Linux
Use snprintf
to construct the command string passed to popen.
FILE * proc;
char command[70];
char a[]="Encrypted data";
int len;
len = snprintf(command, sizeof(command), "openssl aes-256-cbc -d -a -salt %s",a);
if (if len <= sizeof(command))
{
proc = popen(command, "r");
}
else
{
// command buffer too short
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With