Hi there!
I need to your help very much,I've tried so much to solve my
problem,but I couldn't unfortunately!
I want to use of "CryptoPP" library in my project(which is a smart
card CSP).
I'm using of Visual Studio 2008 and "CryptoPP 5.5.2" version!

I need two works:
1. generating an RSA 1024-bit keypair and sign/verify a message.
2. hashing a message with SHA1 algorithm.

Mr. Jeffrey Walton introduced me some sample codes about Generate
RSAkeypair,RSA Sign and RSA verify from this link address:

I built all of them successfully!

But I want to store keys in two explicit "byte array" which can then
use of them in my project,(because I've defined two "byte array" in my
project that want to transfer and store generated RSA keypair into
them!).

In the maintained codes,keys are stored in two files.
Mr. Jeffrey Walton suggested me that use "Arraysink/Arraysource"
instead of "Filesink/Filesource". I did so and tried to store
generated keys in two "Byte Array" named "byte * PrivateArray" and
"byte * PublicArray" instead of two files!

And tried to get help of "Crypto++ user's guide" examples.
This is my code that tried to store keys in two byte array that then
will transfer their contents into two "Byte Array" defined in my
project:


#include "stdafx.h"

// Crypto++ Includes
#include "rsa.h"
#include "osrng.h"  // PRNG
#include "hex.h"    // Hex Encoder/Decoder
#include "filters.h" //Array Source/Sink
int main(int argc, char* argv[])
{

    try
    {
        byte * PrivateArray;
        byte * PublicArray;

        CryptoPP::AutoSeededRandomPool rng;

        // Specify 1024 bit modulus, accept e = 17
        CryptoPP::RSAES_OAEP_SHA_Decryptor Decryptor( rng, 1024 /*, e
*/ );
        CryptoPP::HexEncoder privArray(new
            CryptoPP::ArraySink( PrivateArray,sizeof(PrivateArray) )
        ); // Hex Encoder

        Decryptor.DEREncode(privArray);
        privArray.MessageEnd();
        cout <<" Private key is: ";
        CryptoPP::HexEncoder(privArray).Get(PrivateArray, sizeof
(PrivateArray));
        cout << endl;


        CryptoPP:: RSAES_OAEP_SHA_Encryptor Encryptor(Decryptor);
        CryptoPP::HexEncoder pubArray(new
        CryptoPP::ArraySink(PublicArray,sizeof(PublicArray) )
        ); // Hex Encoder
        Encryptor.DEREncode(pubArray);
        pubArray.MessageEnd();
        cout <<" Public key is: ";
        CryptoPP::HexEncoder(pubArray).Get(PublicArray, sizeof(PublicArray));
        cout << endl;
    }

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

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

        return 0;
}


But after compiling, I got these errors about "cout" and etc:



------ Build started: Project: RSAKeyGen, Configuration: Debug Win32
------
Compiling...
RSAKeyGen.cpp
d:\rsakeygen.cpp(28) : error C2065: 'cout' : undeclared identifier
d:\rsakeygen.cpp(30) : error C2065: 'cout' : undeclared identifier
d:\rsakeygen.cpp(30) : error C2065: 'endl' : undeclared identifier
d:\rsakeygen.cpp(39) : error C2065: 'cout' : undeclared identifier
d:\rsakeygen.cpp(41) : error C2065: 'cout' : undeclared identifier
d:\rsakeygen.cpp(41) : error C2065: 'endl' : undeclared identifier
d:\rsakeygen.cpp(45) : error C2039: 'cerr' : is not a member of 'std'
d:\rsakeygen.cpp(45) : error C2065: 'cerr' : undeclared identifier
d:\rsakeygen.cpp(49) : error C2039: 'cerr' : is not a member of 'std'
d:\rsakeygen.cpp(49) : error C2065: 'cerr' : undeclared identifier

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




I used of namespace "std::" to solve this problem and changed these
lines of code as below:

std::cout <<" Private key is: ";
std::cout << std::endl;
std::cout <<" Public key is: ";
std::cout << std::endl;


And then I got these errors:


------ Build started: Project: RSAKeyGen, Configuration: Debug Win32
------
Compiling...
RSAKeyGen.cpp
d:\rsakeygen.cpp(26) : error C2039: 'cout' : is not a member of 'std'
d:\rsakeygen.cpp(26) : error C2065: 'cout' : undeclared identifier
d:\rsakeygen.cpp(28) : error C2039: 'cout' : is not a member of 'std'
d:\rsakeygen.cpp(28) : error C2065: 'cout' : undeclared identifier
d:\rsakeygen.cpp(28) : error C2563: mismatch in formal parameter list
d:\rsakeygen.cpp(28) : error C2568: '<<' : unable to resolve function
overload
        e:\microsoft visual studio 9.0\vc\include\ostream(974): could
be 'std::basic_ostream<_Elem,_Traits> &std::endl
(std::basic_ostream<_Elem,_Traits> &)'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        e:\program files\microsoft visual studio 9.0\vc\include\ostream
(966): or       'std::basic_ostream<_Elem,_Traits> &std::endl
(std::basic_ostream<_Elem,_Traits> &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\microsoft visual studio 9.0\vc\include\ostream(940):
or       'std::basic_ostream<_Elem,_Traits> &std::endl
(std::basic_ostream<_Elem,_Traits> &)'

d:\rsakeygen.cpp(37) : error C2039: 'cout' : is not a member of 'std'
d:\rsakeygen.cpp(37) : error C2065: 'cout' : undeclared identifier
d:\rsakeygen.cpp(39) : error C2039: 'cout' : is not a member of 'std'
d:\rsakeygen.cpp(39) : error C2065: 'cout' : undeclared identifier
d:\rsakeygen.cpp(39) : error C2563: mismatch in formal parameter list
d:\rsakeygen.cpp(39) : error C2568: '<<' : unable to resolve function
overload
        e:\microsoft visual studio 9.0\vc\include\ostream(974): could
be 'std::basic_ostream<_Elem,_Traits> &std::endl
(std::basic_ostream<_Elem,_Traits> &)'
        with
        [
            _Elem=wchar_t,
            _Traits=std::char_traits<wchar_t>
        ]
        e:\microsoft visual studio 9.0\vc\include\ostream(966):
or       'std::basic_ostream<_Elem,_Traits> &std::endl
(std::basic_ostream<_Elem,_Traits> &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        e:\microsoft visual studio 9.0\vc\include\ostream(940):
or       'std::basic_ostream<_Elem,_Traits> &std::endl
(std::basic_ostream<_Elem,_Traits> &)'

d:\rsakeygen.cpp(43) : error C2039: 'cerr' : is not a member of 'std'
d:\rsakeygen.cpp(43) : error C2065: 'cerr' : undeclared identifier
d:\rsakeygen.cpp(47) : error C2039: 'cerr' : is not a member of 'std'
d:\rsakeygen.cpp(47) : error C2065: 'cerr' : undeclared identifier

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




In your opinion, what is wrong with this code?

Could I ask you give me some sample codes of those two cryptographic
works maintained above
that use of arrays instead of files?

How can I modify this code as desired and use of it in my project?

I've been so confused and tired and hope you would help me.

Also sample codes included in "Crypto++ user's guide" doesn't match
with
"CryptoPP 5.5.2" version and I really don't know what should I do?

Please help me!
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