2017-04-10 5 views
-1

私は、C++でopensslを使ってRC4からS3fsへの実装を進めています。そして、私は、文字列を含む単純なテキストファイルを暗号化しようとしています:私はサンプルRC4の実装のバグ

を私はsegementation障害を得続けるが、私はなぜわかりません。誰かが私の問題についていくつかの光を当てることができますか?以下は結果であり、それはコードです。

ファイル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
unsigned char * buf; 

をオープンしました。

+0

空の値に初期化して、 'foo >> buf'で上書きする方法はありますか? – Callat

+1

Err、 'unsigned char buf [1024];'?またはそれがどれくらいの大きさであろうと? – EJP

+0

私はそれを試してみましょう。 – Callat

関連する問題