文件处理:读取文件时出现异常错误
程序的输出是这样的:
虽然内容正确
(目前仅在尝试解密产生错误结果时)
,但为什么会出现此错误?
udit@udit-Dabba /opt/lampp/htdocs $ ./a.out
Error reading password from BIO
Error getting password
Salted__�Yq\��v��u�&2�t���-�
程序的代码是这样的 -
#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,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);
}
我想我需要更改文件的读/写模式,但不确定......请指导我我做错了什么???
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,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 ???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在调用
system
之前尝试刷新或关闭fq
和fp
。问题可能是运行 openssl 命令时刚刚写入文件的数据尚未刷新到磁盘。Try either flushing or closing
fq
andfp
before the call tosystem
. 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.如何升级 openssl
升级到最新平台。
OpenSSL Tarball
有关更多信息,请阅读如何使用 Putty 和 yum 命令更新 OpenSSL
how to upgrade openssl
Upgrade to latest Platform.
OpenSSL Tarballs
For more read How to update OpenSSL using Putty and yum command