RC4实现错误 我正在使用C++的OpenSSL实现RC4到S3FS。我正在尝试加密一个包含以下字符串的简单文本文件:

RC4实现错误 我正在使用C++的OpenSSL实现RC4到S3FS。我正在尝试加密一个包含以下字符串的简单文本文件:,c++,openssl,rc4-cipher,C++,Openssl,Rc4 Cipher,我是一个样本 我不断地出现分段错误,但我不知道为什么。有人能解释一下我的问题吗?下面是结果,下面是代码 文件1已打开 文件2已打开 分段故障(堆芯转储) #包括 #包括“rc4附件c” #包括“rc4_skey.c” #包括 #包括 #包括 #包括“rc4.h” #包括 #包括 #包括 使用名称空间std; int main(){ //库特 您尚未初始化此变量。是否有办法初始化为某个空值,以便它被foo>>buf覆盖?错误,无符号字符buf[1024]?或者它应该是什么大小?好的,我会试试。问

我是一个样本

我不断地出现分段错误,但我不知道为什么。有人能解释一下我的问题吗?下面是结果,下面是代码

文件1已打开
文件2已打开
分段故障(堆芯转储)

#包括
#包括“rc4附件c”
#包括“rc4_skey.c”
#包括
#包括
#包括
#包括“rc4.h”
#包括
#包括
#包括
使用名称空间std;
int main(){
//库特

您尚未初始化此变量。

是否有办法初始化为某个空值,以便它被
foo>>buf
覆盖?错误,
无符号字符buf[1024]
?或者它应该是什么大小?好的,我会试试。问题解决了!文本文件仍然没有加密,但这是另一个问题。可能是缺少组件或其他什么。我会继续处理它。谢谢你帮我解决了这个问题!:D
#include<iostream>
#include "rc4_enc.c"
#include "rc4_skey.c"
#include <unistd.h>
#include <sys/syscall.h>
#include <errno.h>
#include "rc4.h"
#include<fstream>
#include<string>
#include<sstream>
using namespace std;

int main(){
//cout << "I work \n"; // Test for compilation
ifstream mytext;
ifstream result;

// apply string stream
 stringstream foo;
 stringstream baz;

mytext.open("sample.txt", ios::binary);
 if(!mytext.good()){
     cout << "File 1 not opened \n";
     return 1;
 }
 else{
     cout << "File 1 opened \n";
     foo << mytext.rdbuf();
 }
 result.open("result.txt", ios::binary);
  if(!result.good()){
     cout << "File 2 not opened \n";
     return 1;
  }
  else{
     cout << "File 2 opened \n";
     baz << result.rdbuf();
  }
char source[6] = "tacos";
//const unsigned char source[] = {'t','a','c','o'};
int len = strlen(source);
RC4_KEY mykey;
unsigned char * buf;
foo >> buf;
RC4_set_key(&mykey,len, buf); // causes segfault?
// make a second buffer and cast it.
unsigned char * muf;
baz >> muf;
RC4(&mykey, sizeof(mytext),buf,muf);

    return 0;
unsigned char * buf;