2011-08-08 16 views
4

SHA1を使ってCrypto ++を使ってランダムなハッシュを生成する必要があります。Crypto ++を使ってSHA1でランダムなハッシュを生成する

#include <cryptopp/sha.h> 
#include <cryptopp/filters.h> 
#include <cryptopp/hex.h> 

... 

CryptoPP::SHA1 sha1; 
string source = "Hello"; //This will be randomly generated somehow 
string hash = ""; 
StringSource(source, true, new HashFilter(sha1, new HexEncoder(new StringSink(hash)))); 

私はコンパイルに来たとき、私は次のエラーが報告された取得:私は現時点で

error: expected type-specifier before 'HashFilter' 
error: expected ')' before 'HashFilter' 
error: 'StringSource' was not declared in this scope 

誰も私はこの作業を取得するために助けることができますか?このライブラリを使ってこれを行うもっと簡単な方法がありますか?私はCrypto ++を初めて使用しているので、すべての助けに感謝します。

ありがとうございました。

答えて

8

だけ正確かつ慎重にあなたの名前空間を指定します。

#include <cryptopp/sha.h> 
#include <cryptopp/filters.h> 
#include <cryptopp/hex.h> 

#include <string> 

int main() 
{ 
    CryptoPP::SHA1 sha1; 
    std::string source = "Hello"; //This will be randomly generated somehow 
    std::string hash = ""; 
    CryptoPP::StringSource(source, true, new CryptoPP::HashFilter(sha1, new CryptoPP::HexEncoder(new CryptoPP::StringSink(hash)))); 
} 
+0

グレート、おかげで多くのことを。私は以前これを試したと思ったが、何かが欠けていたに違いない! – MeanwhileInHell

+3

感謝します! cryptoppのドキュメントには**の**例はありません。 – kipple

+0

ドキュメンテーションは、APIリファレンスから見える適切な場所ではありません(あなたはトップページのリンクについて話しています)。 [Crypto ++ Wiki](http://www.cryptopp.com/wiki/Main_Page)を試してみてください。特に、[サンプルカテゴリ](http://www.cryptopp.com/wiki/Category:Sample)。 – jww

関連する問題