Hi friends!
I'm using Visual C++ 2008 and "CryptoPP 5.5.2" version!
I've built the code below successfully:

#include "stdafx.h"

#include "rsa.h"
#include "osrng.h"   // PRNG
#include "hex.h"     // Hex Encoder/Decoder
#include "files.h"   // File Source and Sink

int main(int argc, char* argv[])
{
   try
   {
      CryptoPP::AutoSeededRandomPool rng;
      std::string message = "Yoda said, Do or Do Not. There is not
try.";

      // Input: Private Key
      std::string PrivateKeyFile = "key.pv";

      // Output: Signed Message M
      std::string SignedFile = "message.sig";

      CryptoPP::FileSource privFile( PrivateKeyFile.c_str(), true,
new

CryptoPP::HexDecoder);
      CryptoPP::RSASSA_PKCS1v15_SHA_Signer priv(privFile);

      // Sign Away...
      CryptoPP::StringSource( message, true,
         new CryptoPP::SignerFilter( rng, priv,
            new CryptoPP::HexEncoder(
               new CryptoPP::FileSink( SignedFile.c_str() )
            ) // HexEncoder
         ) // SignerFilter
      ); // StringSource

   } // try

   catch( CryptoPP::Exception& e ) {
      std::cerr << "Error: " << e.what() << std::endl;
   }

   catch (...) {
      std::cerr << "Unknown Error" << std::endl;
   }

   return 0;
}




Then I decided to remove scope sections("CryptoPP::" and "std::") form
code, such below:


#include "stdafx.h"

#include "rsa.h"
#include "osrng.h"   // PRNG
#include "hex.h"     // Hex Encoder/Decoder
#include "files.h"   // File Source and Sink

int main()
{
   try
   {
      AutoSeededRandomPool rng;
      string message = "Yoda said, Do or Do Not. There is not try.";

      // Input: Private Key
      string PrivateKeyFile = "key.pv";

      // Output: Signed Message M
      string SignedFile = "message.sig";

      FileSource privFile( PrivateKeyFile.c_str(), true, new
HexDecoder);
      RSASSA_PKCS1v15_SHA_Signer priv(privFile);

      // Sign Away...
      StringSource( message, true,
         new SignerFilter( rng, priv,
            new HexEncoder(
               new FileSink( SignedFile.c_str() )
            ) // HexEncoder
         ) // SignerFilter
      ); // StringSource

   } // try

   catch( Exception& e ) {
      cerr << "Error: " << e.what() << endl;
   }

   catch (...) {
      cerr << "Unknown Error" << endl;
   }

   return 0;
}



And then got 35 errors as following:


------ Build started: Project: RSASign, Configuration: Debug Win32
------
Compiling...
RSASign.cpp
d:\rsasign.cpp(12) : error C2065: 'AutoSeededRandomPool' : undeclared
identifier
d:\rsasign.cpp(12) : error C2146: syntax error : missing ';' before
identifier 'rng'
d:\rsasign.cpp(12) : error C2065: 'rng' : undeclared identifier
d:\rsasign.cpp(13) : error C2065: 'string' : undeclared identifier
d:\rsasign.cpp(13) : error C2146: syntax error : missing ';' before
identifier 'message'
d:\rsasign.cpp(13) : error C2065: 'message' : undeclared identifier
d:\rsasign.cpp(16) : error C2065: 'string' : undeclared identifier
d:\rsasign.cpp(16) : error C2146: syntax error : missing ';'
before

identifier'PrivateKeyFile'
d:\rsasign.cpp(16) : error C2065: 'PrivateKeyFile' : undeclared
identifier
d:\rsasign.cpp(19) : error C2065: 'string' : undeclared identifier
d:\rsasign.cpp(19) : error C2146: syntax error : missing ';' before
identifier 'SignedFile'
d:\rsasign.cpp(19) : error C2065: 'SignedFile' : undeclared identifier
d:\rsasign.cpp(21) : error C2065: 'FileSource' : undeclared identifier
d:\rsasign.cpp(21) : error C2146: syntax error : missing ';' before
identifier 'privFile'
d:\rsasign.cpp(21) : error C2065: 'PrivateKeyFile' : undeclared
identifier
d:\rsasign.cpp(21) : error C2228: left of '.c_str' must have class/
struct/union
        type is ''unknown-type''
d:\rsasign.cpp(21) : error C2061: syntax error : identifier
'HexDecoder'
d:\rsasign.cpp(21) : error C3861: 'privFile': identifier not found
d:\rsasign.cpp(22) : error C2065: 'RSASSA_PKCS1v15_SHA_Signer' :
undeclared identifier
d:\rsasign.cpp(22) : error C2146: syntax error : missing ';' before
identifier 'priv'
d:\rsasign.cpp(22) : error C2065: 'privFile' : undeclared identifier
d:\rsasign.cpp(22) : error C3861: 'priv': identifier not found
d:\rsasign.cpp(25) : error C2065: 'message' : undeclared identifier
d:\rsasign.cpp(26) : error C2061: syntax error : identifier
'SignerFilter'
d:\rsasign.cpp(26) : error C2065: 'priv' : undeclared identifier
d:\rsasign.cpp(27) : error C2061: syntax error : identifier
'HexEncoder'
d:\rsasign.cpp(35) : error C2061: syntax error : identifier
'Exception'
d:\rsasign.cpp(35) : error C2310: catch handlers must specify one type
d:\rsasign.cpp(36) : error C2065: 'cerr' : undeclared identifier
d:\rsasign.cpp(36) : error C2065: 'e' : undeclared identifier
d:\rsasign.cpp(36) : error C2228: left of '.what' must have class/
struct/union
        type is ''unknown-type''
d:\rsasign.cpp(36) : error C2065: 'endl' : undeclared identifier
d:\rsasign.cpp(25) : error C3861: 'StringSource': identifier not found
d:\rsasign.cpp(40) : error C2065: 'cerr' : undeclared identifier
d:\rsasign.cpp(40) : error C2065: 'endl' : undeclared identifier

RSASign - 35 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========


Now my question is that why sould the codes using "CryptoPP"
library,have this scopes in

themselves certainly?
Though  we use necessary "Header Files" and have added this library to
Visual studio

environment,why should we maintain these scopes("CryptoPP::" and
"std::") in the codes

again?
Why is this work necessary?

Thank you!
Gary
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---

Reply via email to