i might use the wrong way to examine the variables. i just use "cout" to show the variables. fyi, i used Crypto++ 4.2 on Windows 2000, MS Visual C++ (MS Visual Studio).
the output below (it might shows different from what i sent), is based of the fixed seed. both PrivateKeys are empty and the Agreed Values are not identical.
attached the coding.
thank you very much.
---------------------Output---------------------------------------------
acPrivateKeyA:
acPublicKeyA: �gⁿg/�w��≡─╛�↨[
acPrivateKeyB:
acPublicKeyB: ���S↑�Xδ����╪◄�╛
acAgreedValueA: xV/4y�G∩sN╙�4�╩����S↑�Xδ����╪◄�╛
acAgreedValueB: xV/4y�G∩sN╙�4�╩�xV/4y�G∩sN╙�4�╩����S↑�Xδ����╪◄�╛
---------------------Code----------------------------------------------- #include "randpool.h" #include "dh.h" #include <iostream>
USING_NAMESPACE(CryptoPP) USING_NAMESPACE(std)
void main () {
// Alice
// Create auto seeded random number generator
// CryptoPP::AutoSeededRandomPool autorng = CryptoPP::AutoSeededRandomPool();
char* Seed = "seed"; RandomPool randPool; randPool.Put((byte *)Seed, strlen((char*)Seed));
// Create diffie hellman class CryptoPP::DH dhDHA = CryptoPP::DH(randPool, 128);
// Get prime and generator CryptoPP::Integer integerPrimeA = dhDHA.GetPrime(); CryptoPP::Integer integerGeneratorA = dhDHA.GetGenerator();
// Store prime and generator values int iCounter = 0;
byte acPrimeA[16] = {0};
for (iCounter = 0; iCounter < 16; iCounter++)
{
acPrimeA[iCounter] = integerPrimeA.GetByte(iCounter);
}byte cGeneratorA[16]={0};
for (iCounter = 0; iCounter < 16; iCounter++)
{
cGeneratorA[iCounter] = integerGeneratorA.GetByte(iCounter);
}// Generate key pair
byte acPrivateKeyA[16] = {0};
byte acPublicKeyA[16] = {0};
dhDHA.GenerateKeyPair(randPool, acPrivateKeyA, acPublicKeyA);cout << "acPrivateKeyA: " << acPrivateKeyA << endl; cout << "acPublicKeyA: " << acPublicKeyA << endl;
// Bob
// Get prime and generator from Alice
CryptoPP::Integer integerPrimeB;
for (iCounter = 0; iCounter < 16; iCounter++)
{
integerPrimeB.SetByte(iCounter, acPrimeA[iCounter]);
}CryptoPP::Integer integerGeneratorB;
for (iCounter = 0; iCounter < 16; iCounter++)
{
integerGeneratorB.SetByte(iCounter, cGeneratorA[iCounter]);
}// Create diffie hellman class based on Alice's p and g DH dhDHB (integerPrimeB, integerGeneratorB);
// Generate key pair
byte acPrivateKeyB[16] = {0};
byte acPublicKeyB[16] = {0};
dhDHB.GenerateKeyPair(randPool, acPrivateKeyB, acPublicKeyB);cout << "acPrivateKeyB: " << acPrivateKeyB << endl; cout << "acPublicKeyB: " << acPublicKeyB << endl;
// To calculate agreed value between Alice and Bob
byte acAgreedValueA[16] = {0};
dhDHA.Agree(acAgreedValueA, acPrivateKeyA, acPublicKeyB, true);
byte acAgreedValueB[16] = {0};
dhDHB.Agree(acAgreedValueB, acPrivateKeyB, acPublicKeyA, true);cout << "acAgreedValueA: " << acAgreedValueA<< endl; cout << "acAgreedValueB: " << acAgreedValueB<< endl;
}
------------------------------------------------------------------------
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail
