Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // gcc -o myap openssl.c -lcrypto
- #include "openssl/aes.h"
- #include "string.h"
- #include "stdio.h"
- int main (int i, char** b){
- char filename[] = "file.txt";
- FILE *file = fopen ( filename, "r" );
- char key[] = "mysecretpassword";
- if (file != NULL) {
- char line [1000];
- char *p = line;
- char *array = line;
- while(fgets(line,sizeof line,file)!= NULL) {
- int ivSize = 16;
- int strLen = strlen(line) - ivSize;
- fprintf(stdout,"%s\n",line);
- char otherString[strLen + 1];
- strncpy(otherString, p, strLen);
- otherString[strLen] = '\0';
- printf("%s \n", otherString);//Here I got the Encrypted string
- array = array + strLen;
- printf("%s \n",array);//Here I got the IV
- char buffer[1000];
- AES_KEY dec_key;
- AES_set_decrypt_key(key, 128, &dec_key);
- AES_cbc_encrypt(otherString, buffer, strLen, &dec_key, array, AES_DECRYPT);
- printf("result is: %s\n", buffer);
- //Here how to decrypt the Cipher text using "IV" and "key"
- }
- fclose(file);
- }
- else {
- perror(filename);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment