The output of the program is this :
Although correct contents
(for now only when trying to decrypt producing wrong result)
but why this error ??
udit@udit-Dabba /opt/lampp/htdocs $ ./a.out
Error reading password from BIO
Error getting password
Salted__�Yq\��v��u�&2�t���-�
The code for program is this -
#include <stdio.h>
#include <stdint.h>
void crypto(uint8_t *key, uint32_t keylen, uint8_t *data, uint32_t datalen);
int main () {
uint8_t icv[10]="uditgupta";
uint8_t ekey[14]="1234567891011";
uint8_t *key=ekey;
uint8_t *data=icv;
crypto(ekey,13,icv,9);
return 0;
}
void crypto(uint8_t *key, uint32_t keylen,uint8_t *data, uint32_t datalen)
{
int ch,i;
uint8_t mydata[100],modata[100];
uint8_t *p=mydata;
FILE *fp,*fq,*fr;
fp=fopen("key","w");
fputs(key开发者_JS百科,fp);
fq=fopen("file.txt","w");
fputs(data,fq);
memset(data,0,sizeof(data));
system("sudo openssl enc -aes-256-cbc -salt -in file.txt
-out file.enc -pass file:key");
fr=fopen("file.enc","r");
memset(mydata,0,sizeof(mydata));
i=0;
while( (ch=fgetc(fr)) != EOF) {
mydata[i]=ch;
i++;
}
i=0;
puts(p);
}
I think i need to change the read/write mode of file but not sure...Please guide me what an I doing wrong ???
Try either flushing or closing fq
and fp
before the call to system
. The problem is probably that the data you have just written to the files has not been flushed to disk yet when the openssl command is run.
how to upgrade openssl
Upgrade to latest Platform.
OpenSSL Tarballs
For more read How to update OpenSSL using Putty and yum command
精彩评论