Hi people im new here. I want to work with security but i got many issues with this simple program.
I want to encrypt and decrypt a msg with openssl cmds. Btw im using pipeline and process open (popen) function. Im using Fedora gcc to compile. Any help, recommendations will be appreciate. Thankss! =)
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main() {
FILE * read_fp;
char buffer [BUFSIZ + 1];
int chars_read;
memset (buffer, '\0', sizeof(buffer));
int selection;
printf("Menu Security\n");
printf("\n\t1. Encrypt a message \n\t2. Decrypt a message\n\t3. Exit\n");
printf("\nChoose an option: ");
scanf("%d", &selection);
switch(selection){
case 1:
read_fp = popen ("openssl enc -aes-256-cbc -salt -in file.txt -out file.enc","r");
/*printf("Encrypted Successful\n");*/
/*printf("Encrypted Failed, Password Doesn't Match. Please Try Again!\n");*/
break;
case 2:
popen ("openssl enc -aes-256-cbc -salt -in file.txt -out file.enc","w");*/
printf("Decrypted Successful\n");
/*printf("Decrypted Failed, Password Doesn't Match. Please Try Again!\n");*/
break;
case 3:
exit(EXIT_SUCCESS);;
break;
default:
printf("Invalid selection, Please Try Again!\n");
break;
}
/*return 0;*/
/*END MENU*/
if (read_fp!=NULL){
chars_read = fread (buffer, sizeof(char), BUFSIZ, read_fp);
if (chars_read > 0){
buffer [chars_read -1] = '\0';
printf("Reading: -\n%s\n", buffer);
chars_read = fread(buffer,sizeof(char),BUFSIZ,read_fp);
}
/*while (chars_read > 0) {
buffer[chars_read - 1] = '\0';
printf("Reading:-\n %s\n", buffer);
chars_read = fread(buffer, sizeof(char), BUFSIZ, read_fp);
}*/
pclose(read_fp);
}
}