文件处理:读取文件时出现异常错误

发布于 2024-12-07 08:56:19 字数 1206 浏览 0 评论 0原文

程序的输出是这样的:

虽然内容正确

(目前仅在尝试解密产生错误结果时)

,但为什么会出现此错误?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾城月光淡如水﹏ 2024-12-14 08:56:19

在调用 system 之前尝试刷新或关闭 fqfp。问题可能是运行 openssl 命令时刚刚写入文件的数据尚未刷新到磁盘。

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.

像你 2024-12-14 08:56:19

如何升级 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文