Hello
Thank you Mr. Beresford.
Your advice was so helpfull!

I changed the code based on your suggestion,
1-Include the "files.h"
2-change Hashmodule to HashTransformation
as below:


such below:

// Crypto++
 #include "sha.h"        // SHA-1, SHA-256, SHA-384, SHA-512
 #include "hex.h"        // HexEncoder
 #include "files.h"

 // std
 #include <iostream>
 #include <string.h>
void DumpHash_SingleStep(
     CryptoPP::HashTransformation& hash,
     char const* szModuleName,
     std::string const& strData)
 {
     using namespace std;
     using namespace CryptoPP;

     // Cannot use std::string for buffer;
     // its internal storage might not be contiguous
     SecByteBlock sbbDigest(hash.DigestSize());

     hash.CalculateDigest(
         sbbDigest.Begin(),
         (byte const*) strData.data(),
         strData.size());

     cout << szModuleName << " SS: ";
     HexEncoder(new FileSink(cout)).Put(sbbDigest.Begin(),
sbbDigest.Size());
     cout << endl;
 }
void DumpHash_MultiStep(
     CryptoPP::HashTransformation& hash,
     char const* szModuleName,
     std::string const& strDataPart1,
     std::string const& strDataPart2,
     std::string const& strDataPart3)
 {
     using namespace std;
     using namespace CryptoPP;

     hash.Update((byte const*) strDataPart1.data(), strDataPart1.size
());
     hash.Update((byte const*) strDataPart2.data(), strDataPart2.size
());
     hash.Update((byte const*) strDataPart3.data(), strDataPart3.size
());

     // Cannot use std::string for buffer;
     // its internal storage might not be contiguous
     SecByteBlock sbbDigest(hash.DigestSize());

     hash.Final(sbbDigest.Begin());

     cout << szModuleName << " MS: ";
     HexEncoder(new FileSink(cout)).Put(sbbDigest.Begin(),
sbbDigest.Size());
     cout << endl;
 }
void DumpHash_HashFilter(
     CryptoPP::HashTransformation& hash,
     char const* szModuleName,
     std::string const& strDataPart1,
     std::string const& strDataPart2,
     std::string const& strDataPart3)
 {
     using namespace std;
     using namespace CryptoPP;

     // Here, we are free to use std::string as the destination,
     // because StringSink uses the correct std::string interface to
append data
     string strDigest;
     HashFilter hashFilter(hash, new StringSink(strDigest));
     hashFilter.Put((byte const*) strDataPart1.data(),
strDataPart1.size());
     hashFilter.Put((byte const*) strDataPart2.data(),
strDataPart2.size());
     hashFilter.Put((byte const*) strDataPart3.data(),
strDataPart3.size());
     hashFilter.MessageEnd();

     cout << szModuleName << " HF: ";
     StringSource(strDigest, true,
         new HexEncoder(
             new FileSink(cout)));
     cout << endl;
 }
void DumpHash(
     CryptoPP::HashTransformation& hash,
     char const* szModuleName,
     std::string const& strDataPart1,
     std::string const& strDataPart2,
     std::string const& strDataPart3)
 {
     DumpHash_SingleStep(hash, szModuleName, strDataPart1 +
strDataPart2 + strDataPart3);
     DumpHash_MultiStep(hash, szModuleName, strDataPart1,
strDataPart2, strDataPart3);
     DumpHash_HashFilter(hash, szModuleName, strDataPart1,
strDataPart2, strDataPart3);
 }
 int main()
 {
     using namespace std;
     using namespace CryptoPP;

     std::string strDataPart1 = "part 1; ";
     std::string strDataPart2 = "part two; ";
     std::string strDataPart3 = "PART THREE.";

     try
     {
         DumpHash(SHA(),       "SHA      ", strDataPart1,
strDataPart2, strDataPart3);
         DumpHash(SHA256(),    "SHA256   ", strDataPart1,
strDataPart2, strDataPart3);
     }
     catch (CryptoPP::Exception const& e)
     {
         cout << "CryptoPP::Exception caught: " << endl
              << e.what() << endl;
         return 1;
     }

     return 0;
 }

Most of errors are removed!
But still there are 6 error as below:


------ Build started: Project: cryptopp(hashmodule), Configuration:
Debug Win32 ------
Compiling...
1.cpp
d:\cryptopp(hashmodule)\1.cpp(22) : error C2039: 'Begin' : is not a
member of

'CryptoPP::SecBlock<T>'
        with
        [
            T=byte
        ]
d:\cryptopp(hashmodule)\1.cpp(27) : error C2039: 'Begin' : is not a
member of

'CryptoPP::SecBlock<T>'
        with
        [
            T=byte
        ]
d:\cryptopp(hashmodule)\1.cpp(27) : error C2039: 'Size' : is not a
member of

'CryptoPP::SecBlock<T>'
        with
        [
            T=byte
        ]
d:\cryptopp(hashmodule)\1.cpp(48) : error C2039: 'Begin' : is not a
member of

'CryptoPP::SecBlock<T>'
        with
        [
            T=byte
        ]
d:\cryptopp(hashmodule)\1.cpp(51) : error C2039: 'Begin' : is not a
member of

'CryptoPP::SecBlock<T>'
        with
        [
            T=byte
        ]
d:\cryptopp(hashmodule)\1.cpp(51) : error C2039: 'Size' : is not a
member of

'CryptoPP::SecBlock<T>'
        with
        [
            T=byte
        ]

cryptopp(hashmodule) - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========



I looked at Cryptopp reference,but didn't find "SecByteBlock"
definition!
I just found "FixedSizeSecBlock" type which didn't help me to correct
the code,please help

me again which type should I use instead of "SecByteBlock" type?(I'm
using "Cryptopp5.5.2"

package!)


And in the code you have placed here,I see these changes:

 #include "./cryptlib/hex.h"
 #include "./cryptlib/files.h"
 #include "./cryptlib/cryptlib.h"
 #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
*******************
 #include "./cryptlib/sha.h"
 #include "./cryptlib/ripemd.h"
 #include "./cryptlib/md5.h"
 #include "./cryptlib/crc.h"
*******************
 SHA sha;
 SHA256 sha256;
 RIPEMD160 ripemd160;
 Weak::MD5 md5;
 CRC32 crc32;

But I don't try your code with these changes in VC++ 2008 yet, I will
try it and tell you the result!


And the other request!

I want to use from "Cryptopp" library in my project(implementing a
Smart Card CSP).
I only want to use RSA algorithm to sign and verify (not encrypt/
decrypt) with 1024-bit key size, and to use SHA1 algorithm for
hashing!

- Could you give me some sample codes of using these "Cryptopp"
functions to sign and hash in version 5.5.2 of "Cryptopp" library?

(Because there isn't any sample code of implementing this tasks in
"Reference" and unfortunately I have not much time to try use of each
function!
As you know,Sample codes in "Crypto++ user's guide" don't match with
version 5.5.2 of Cryptopp library as well!)

Any help will be greatly appreciated.
I'm waiting for your help Dear Dillon!
Regards.




On Feb 1, 1:44 am, Dillon Beresford <[email protected]>
wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> Gary,
>
> I looked at the code and you will need to use
> CryptoPP::HashTransformation instead of the old CryptoPP::HashModule
> which is defined in cryptlib.h it was a predecessor to
> HashTransformation in Crypto++ 4.2. I believe you are using Wei's
> latest Crypto++ 5.5.2 build in which HashModule has been deprecated.
> You mentioned in your email that your using Crypto++ 5.5.2 with Visual
> Studio so that kind of explains why your getting errors during the
> build process. I also see a class reference to FileSink you will need
> the proper include which is #include "files.h". As for compiling the
> libs,
> yes, I would suggest you compile the cryptlibd and cryptlib for your
> release and debug builds.!
>
> Reference to 
> HashTransformation:http://www.cryptopp.com/docs/ref/class_hash_transformation.html
>
> In response to another question posted on the group in which this
> topic came up.
>
> http://www.mail-archive.com/[email protected]/msg00101.html
>
> void DumpHash_SingleStep(CryptoPP::HashTransformation& hash, char
> const* szModuleName, std::string const& strData) { // Code }
>
> Moreover, the syntax errors are pretty straightforward.
>
> HexEncoder(new FileSink(cout)).Put(sbbDigest.Begin(), // sbbDigest.begin()
>
> See these topics and see if they  help, I was able to compile this
> code using the proper version of the Crypto++ 4.2
>
> http://www.linuxdiyf.com/viewarticle.php?id=109184
>
> http://blog.csdn.net/violetfeeling/archive/2008/09/19/2949701.aspx
>
> I'm sure Mr. Dai will have more insightful information regarding
> HashModule and HashTransformation.
>
> Regards,
>
> Dillon Beresford
> The Komodo PGMP 
> projecthttp://code.google.com/p/komodopgmp/http://sourceforge.net/projects/komodopgmp/
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org
>
> iD8DBQFJhNRoRnxC5lZRuuERAtFBAJ9OrROS9XvLhBfNP1ZpGSkJaiBylQCeI/xj
> hh7dvN8927jYs0hCHyw6Oy8=
> =eJQl
> -----END PGP SIGNATURE-----
>
> [HashTrans.cpp4K ]//codes in userguide, cryptlib.h, DumpHashes.cpp
>
> #include "./cryptlib/hex.h"
> #include "./cryptlib/files.h"
> #include "./cryptlib/cryptlib.h"
> #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
>
> #include <iostream>
> #include <string.h>
>
> using namespace std;
> using namespace CryptoPP;
>
> void DumpHash_SingleStep(CryptoPP::HashTransformation& hash, char const* 
> szModuleName, std::string const& strData) {
> //Can't use std::string for buffer;
> // its internal storage might not be contiguous
> SecByteBlock sbbDigest(hash.DigestSize());
>
> hash.CalculateDigest(sbbDigest.begin(), (byte const*) strData.data(), 
> strData.size());
>
> cout << szModuleName << "SS:";
> HexEncoder(new FileSink(cout)).Put(sbbDigest.begin(), sbbDigest.size());
> cout << endl;
>
> }
>
> void DumpHash_MultiStep(CryptoPP::HashTransformation& hash, char const* 
> szModuleName, std::string const& strDataPart1, std::string const& 
> strDataPart2, std::string const& strDataPart3){
> hash.Update((byte const*) strDataPart1.data(), strDataPart1.size());
> hash.Update((byte const*) strDataPart2.data(), strDataPart2.size());
> hash.Update((byte const*) strDataPart3.data(), strDataPart3.size());
>
> //can't use std::string for buffer;
> //its internal storage might not be contiguous
> SecByteBlock sbbDigest(hash.DigestSize());
>
> hash.Final(sbbDigest.begin());
>
> cout << szModuleName << "MS";
> HexEncoder(new FileSink(cout)).Put(sbbDigest.begin(), sbbDigest.size());
> cout << endl;
>
> }
>
> void DumpHash_HashFilter(CryptoPP::HashTransformation& hash, char const* 
> szModuleName, std::string const& strDataPart1, std::string const& 
> strDataPart2, std::string const& strDataPart3){
> //Here, we are free to use std::string as the destination,
> //because StringSink uses the correct std::string interface to append data
> string strDigest;
> HashFilter hashFilter(hash, new StringSink(strDigest));
> hashFilter.Put((byte const*) strDataPart1.data(), strDataPart1.size());
> hashFilter.Put((byte const*) strDataPart2.data(), strDataPart2.size());
> hashFilter.Put((byte const*) strDataPart3.data(), strDataPart3.size());
> hashFilter.MessageEnd();
>
> cout << szModuleName << "HF:";
> StringSource(strDigest, true, new HexEncoder(new FileSink(cout)));
> cout << endl;
>
> }
>
> void DumpHash(CryptoPP::HashTransformation& hash, char const* szModuleName, 
> std::string const& strDataPart1, std::string const& strDataPart2, std::string 
> const& strDataPart3){
> DumpHash_SingleStep(hash, szModuleName, strDataPart1 + strDataPart2 + 
> strDataPart3);
> DumpHash_MultiStep(hash, szModuleName, strDataPart1, strDataPart2, 
> strDataPart3);
> DumpHash_HashFilter(hash, szModuleName, strDataPart1, strDataPart2, 
> strDataPart3);
>
> }
>
> //Crypto++
> #include "./cryptlib/sha.h"
> #include "./cryptlib/ripemd.h"
> #include "./cryptlib/md5.h"
> #include "./cryptlib/crc.h"
>
> int main(){
> using namespace std;
> using namespace CryptoPP;
>
> SHA sha;
> SHA256 sha256;
> RIPEMD160 ripemd160;
> Weak::MD5 md5;
> CRC32 crc32;
>
> std::string strDataPart1 = "part 1;";
> std::string strDataPart2 = "part two;";
> std::string strDataPart3 = "PART THREE;";
>
> try{
> DumpHash(sha, "SHA", strDataPart1, strDataPart2, strDataPart3);
> DumpHash(sha256, "SHA256", strDataPart1, strDataPart2, strDataPart3);
> DumpHash(ripemd160, "RIPEMD160", strDataPart1, strDataPart2, strDataPart3);
> DumpHash(md5, "MD5", strDataPart1, strDataPart2, strDataPart3);
> DumpHash(crc32, "CRC32", strDataPart1, strDataPart2, strDataPart3);}
>
> catch(CryptoPP::Exception const& e){
> cout << "CryptoPP::Exception caught:" << endl
> << e.what() << endl;
> return 1;
>
> }
> }
>
>
>
>  pgpkeys.asc
> 2KViewDownload
--~--~---------~--~----~------------~-------~--~----~
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