RC4实现错误

时间:2017-04-10 23:57:46

标签: c++ openssl rc4-cipher

我正在使用带有C ++的openssl来实现RC4到S3fs的实现。我正在尝试加密包含字符串的简单文本文件:

  

我是一个样本

我一直遇到分裂错误,但我不确定为什么。有谁可以解释我的问题?下面是结果,下面是代码。

  

文件1打开了   文件2打开了   分段故障(核心转储)

#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;

1 个答案:

答案 0 :(得分:1)

unsigned char * buf;

您尚未初始化此变量。