本文整理汇总了C++中AsymmetricKeyPair::serialise方法的典型用法代码示例。如果您正苦于以下问题:C++ AsymmetricKeyPair::serialise方法的具体用法?C++ AsymmetricKeyPair::serialise怎么用?C++ AsymmetricKeyPair::serialise使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsymmetricKeyPair
的用法示例。
在下文中一共展示了AsymmetricKeyPair::serialise方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testSerialisation
void DSATests::testSerialisation()
{
// Generate 1024-bit parameters for testing
DSAParameters* p;
AsymmetricParameters** ap = (AsymmetricParameters**) &p;
CPPUNIT_ASSERT(dsa->generateParameters(ap, (void*) 1024));
// Serialise the parameters
ByteString serialisedParams = p->serialise();
// Deserialise the parameters
AsymmetricParameters* dP;
CPPUNIT_ASSERT(dsa->reconstructParameters(&dP, serialisedParams));
CPPUNIT_ASSERT(dP->areOfType(DSAParameters::type));
DSAParameters* ddP = (DSAParameters*) dP;
CPPUNIT_ASSERT(p->getP() == ddP->getP());
CPPUNIT_ASSERT(p->getQ() == ddP->getQ());
CPPUNIT_ASSERT(p->getG() == ddP->getG());
// Generate a key-pair
AsymmetricKeyPair* kp;
CPPUNIT_ASSERT(dsa->generateKeyPair(&kp, dP));
// Serialise the key-pair
ByteString serialisedKP = kp->serialise();
// Deserialise the key-pair
AsymmetricKeyPair* dKP;
CPPUNIT_ASSERT(dsa->reconstructKeyPair(&dKP, serialisedKP));
// Check the deserialised key-pair
DSAPrivateKey* privKey = (DSAPrivateKey*) kp->getPrivateKey();
DSAPublicKey* pubKey = (DSAPublicKey*) kp->getPublicKey();
DSAPrivateKey* dPrivKey = (DSAPrivateKey*) dKP->getPrivateKey();
DSAPublicKey* dPubKey = (DSAPublicKey*) dKP->getPublicKey();
CPPUNIT_ASSERT(privKey->getP() == dPrivKey->getP());
CPPUNIT_ASSERT(privKey->getQ() == dPrivKey->getQ());
CPPUNIT_ASSERT(privKey->getG() == dPrivKey->getG());
CPPUNIT_ASSERT(privKey->getX() == dPrivKey->getX());
CPPUNIT_ASSERT(pubKey->getP() == dPubKey->getP());
CPPUNIT_ASSERT(pubKey->getQ() == dPubKey->getQ());
CPPUNIT_ASSERT(pubKey->getG() == dPubKey->getG());
CPPUNIT_ASSERT(pubKey->getY() == dPubKey->getY());
dsa->recycleParameters(p);
dsa->recycleParameters(dP);
dsa->recycleKeyPair(kp);
dsa->recycleKeyPair(dKP);
}
示例2: testSerialisation
void GOSTTests::testSerialisation()
{
CPPUNIT_ASSERT((gost = CryptoFactory::i()->getAsymmetricAlgorithm("gost")));
// Get GOST R 34.10-2001 params-A domain parameters
ECParameters* p = new ECParameters;
p->setEC(ByteString("06072a850302022301"));
// Serialise the parameters
ByteString serialisedParams = p->serialise();
// Deserialise the parameters
AsymmetricParameters* dEC;
CPPUNIT_ASSERT(gost->reconstructParameters(&dEC, serialisedParams));
CPPUNIT_ASSERT(dEC->areOfType(ECParameters::type));
ECParameters* ddEC = (ECParameters*) dEC;
CPPUNIT_ASSERT(p->getEC() == ddEC->getEC());
// Generate a key-pair
AsymmetricKeyPair* kp;
CPPUNIT_ASSERT(gost->generateKeyPair(&kp, dEC));
// Serialise the key-pair
ByteString serialisedKP = kp->serialise();
// Deserialise the key-pair
AsymmetricKeyPair* dKP;
CPPUNIT_ASSERT(gost->reconstructKeyPair(&dKP, serialisedKP));
// Check the deserialised key-pair
GOSTPrivateKey* privKey = (GOSTPrivateKey*) kp->getPrivateKey();
GOSTPublicKey* pubKey = (GOSTPublicKey*) kp->getPublicKey();
GOSTPrivateKey* dPrivKey = (GOSTPrivateKey*) dKP->getPrivateKey();
GOSTPublicKey* dPubKey = (GOSTPublicKey*) dKP->getPublicKey();
CPPUNIT_ASSERT(privKey->getD() == dPrivKey->getD());
CPPUNIT_ASSERT(pubKey->getQ() == dPubKey->getQ());
gost->recycleParameters(p);
gost->recycleParameters(dEC);
gost->recycleKeyPair(kp);
gost->recycleKeyPair(dKP);
CryptoFactory::i()->recycleAsymmetricAlgorithm(gost);
gost = NULL;
}
示例3: testSerialisation
void ECDSATests::testSerialisation()
{
// Get prime256v1 domain parameters
ECParameters* p = new ECParameters;
p->setEC(ByteString("06082a8648ce3d030107"));
// Serialise the parameters
ByteString serialisedParams = p->serialise();
// Deserialise the parameters
AsymmetricParameters* dEC;
CPPUNIT_ASSERT(ecdsa->reconstructParameters(&dEC, serialisedParams));
CPPUNIT_ASSERT(dEC->areOfType(ECParameters::type));
ECParameters* ddEC = (ECParameters*) dEC;
CPPUNIT_ASSERT(p->getEC() == ddEC->getEC());
// Generate a key-pair
AsymmetricKeyPair* kp;
CPPUNIT_ASSERT(ecdsa->generateKeyPair(&kp, dEC));
// Serialise the key-pair
ByteString serialisedKP = kp->serialise();
// Deserialise the key-pair
AsymmetricKeyPair* dKP;
CPPUNIT_ASSERT(ecdsa->reconstructKeyPair(&dKP, serialisedKP));
// Check the deserialised key-pair
ECPrivateKey* privKey = (ECPrivateKey*) kp->getPrivateKey();
ECPublicKey* pubKey = (ECPublicKey*) kp->getPublicKey();
ECPrivateKey* dPrivKey = (ECPrivateKey*) dKP->getPrivateKey();
ECPublicKey* dPubKey = (ECPublicKey*) dKP->getPublicKey();
CPPUNIT_ASSERT(privKey->getEC() == dPrivKey->getEC());
CPPUNIT_ASSERT(privKey->getD() == dPrivKey->getD());
CPPUNIT_ASSERT(pubKey->getEC() == dPubKey->getEC());
CPPUNIT_ASSERT(pubKey->getQ() == dPubKey->getQ());
ecdsa->recycleParameters(p);
ecdsa->recycleParameters(dEC);
ecdsa->recycleKeyPair(kp);
ecdsa->recycleKeyPair(dKP);
}
示例4: testSerialisation
void RSATests::testSerialisation()
{
// Generate a 1024-bit key-pair for testing
AsymmetricKeyPair* kp;
RSAParameters p;
p.setE("010001");
p.setBitLength(1024);
CPPUNIT_ASSERT(rsa->generateKeyPair(&kp, &p));
CPPUNIT_ASSERT(kp != NULL);
// Serialise the parameters
ByteString serialisedParams = p.serialise();
// Deserialise the parameters
AsymmetricParameters* dP;
CPPUNIT_ASSERT(rsa->reconstructParameters(&dP, serialisedParams));
CPPUNIT_ASSERT(dP->areOfType(RSAParameters::type));
RSAParameters* ddP = (RSAParameters*) dP;
CPPUNIT_ASSERT(p.getE() == ddP->getE());
CPPUNIT_ASSERT(p.getBitLength() == ddP->getBitLength());
rsa->recycleParameters(dP);
// Serialise the key-pair
ByteString serialisedKP = kp->serialise();
CPPUNIT_ASSERT(serialisedKP.size() != 0);
// Deserialise the key-pair
AsymmetricKeyPair* dKP;
CPPUNIT_ASSERT(rsa->reconstructKeyPair(&dKP, serialisedKP));
CPPUNIT_ASSERT(serialisedKP.size() == 0);
CPPUNIT_ASSERT(dKP != NULL);
RSAPublicKey* pub = (RSAPublicKey*) kp->getPublicKey();
RSAPrivateKey* priv = (RSAPrivateKey*) kp->getPrivateKey();
RSAPublicKey* dPub = (RSAPublicKey*) dKP->getPublicKey();
RSAPrivateKey* dPriv = (RSAPrivateKey*) dKP->getPrivateKey();
CPPUNIT_ASSERT(pub->getN() == dPub->getN());
CPPUNIT_ASSERT(pub->getE() == dPub->getE());
CPPUNIT_ASSERT(priv->getP() == dPriv->getP());
CPPUNIT_ASSERT(priv->getQ() == dPriv->getQ());
CPPUNIT_ASSERT(priv->getPQ() == dPriv->getPQ());
CPPUNIT_ASSERT(priv->getDP1() == dPriv->getDP1());
CPPUNIT_ASSERT(priv->getDQ1() == dPriv->getDQ1());
CPPUNIT_ASSERT(priv->getD() == dPriv->getD());
CPPUNIT_ASSERT(priv->getN() == dPriv->getN());
CPPUNIT_ASSERT(priv->getE() == dPriv->getE());
// Serialise and deserialise the public key
ByteString serialisedPub = pub->serialise();
RSAPublicKey* desPub;
CPPUNIT_ASSERT(rsa->reconstructPublicKey((PublicKey**) &desPub, serialisedPub));
CPPUNIT_ASSERT(serialisedPub.size() == 0);
CPPUNIT_ASSERT(desPub != NULL);
CPPUNIT_ASSERT(pub->getN() == desPub->getN());
CPPUNIT_ASSERT(pub->getE() == desPub->getE());
// Serialise and deserialise the private key
ByteString serialisedPriv = priv->serialise();
RSAPrivateKey* desPriv;
CPPUNIT_ASSERT(rsa->reconstructPrivateKey((PrivateKey**) &desPriv, serialisedPriv));
CPPUNIT_ASSERT(serialisedPriv.size() == 0);
CPPUNIT_ASSERT(desPriv != NULL);
CPPUNIT_ASSERT(priv->getP() == desPriv->getP());
CPPUNIT_ASSERT(priv->getQ() == desPriv->getQ());
CPPUNIT_ASSERT(priv->getPQ() == desPriv->getPQ());
CPPUNIT_ASSERT(priv->getDP1() == desPriv->getDP1());
CPPUNIT_ASSERT(priv->getDQ1() == desPriv->getDQ1());
CPPUNIT_ASSERT(priv->getD() == desPriv->getD());
CPPUNIT_ASSERT(priv->getN() == desPriv->getN());
CPPUNIT_ASSERT(priv->getE() == desPriv->getE());
rsa->recycleKeyPair(kp);
rsa->recycleKeyPair(dKP);
rsa->recyclePublicKey(desPub);
rsa->recyclePrivateKey(desPriv);
}
示例5: testSerialisation
void DHTests::testSerialisation()
{
// Generate 1024-bit parameters for testing
DHParameters* p;
AsymmetricParameters** ap = (AsymmetricParameters**) &p;
//CPPUNIT_ASSERT(dh->generateParameters(ap, (void*) 1024));
// changed for 512-bit for speed...
#ifndef WITH_BOTAN
CPPUNIT_ASSERT(dh->generateParameters(ap, (void*) 1024));
#else
CPPUNIT_ASSERT(dh->generateParameters(ap, (void*) 512));
#endif
// Set a fixed private value length
p->setXBitLength(128);
// Serialise the parameters
ByteString serialisedParams = p->serialise();
// Deserialise the parameters
AsymmetricParameters* dP;
CPPUNIT_ASSERT(dh->reconstructParameters(&dP, serialisedParams));
CPPUNIT_ASSERT(dP->areOfType(DHParameters::type));
DHParameters* ddP = (DHParameters*) dP;
CPPUNIT_ASSERT(p->getP() == ddP->getP());
CPPUNIT_ASSERT(p->getG() == ddP->getG());
CPPUNIT_ASSERT(p->getXBitLength() == ddP->getXBitLength());
// Generate a key-pair
AsymmetricKeyPair* kp;
CPPUNIT_ASSERT(dh->generateKeyPair(&kp, dP));
// Serialise the key-pair
ByteString serialisedKP = kp->serialise();
// Deserialise the key-pair
AsymmetricKeyPair* dKP;
CPPUNIT_ASSERT(dh->reconstructKeyPair(&dKP, serialisedKP));
// Check the deserialised key-pair
DHPrivateKey* privKey = (DHPrivateKey*) kp->getPrivateKey();
DHPublicKey* pubKey = (DHPublicKey*) kp->getPublicKey();
DHPrivateKey* dPrivKey = (DHPrivateKey*) dKP->getPrivateKey();
DHPublicKey* dPubKey = (DHPublicKey*) dKP->getPublicKey();
CPPUNIT_ASSERT(privKey->getP() == dPrivKey->getP());
CPPUNIT_ASSERT(privKey->getG() == dPrivKey->getG());
CPPUNIT_ASSERT(privKey->getX() == dPrivKey->getX());
CPPUNIT_ASSERT(pubKey->getP() == dPubKey->getP());
CPPUNIT_ASSERT(pubKey->getG() == dPubKey->getG());
CPPUNIT_ASSERT(pubKey->getY() == dPubKey->getY());
dh->recycleParameters(p);
dh->recycleParameters(dP);
dh->recycleKeyPair(kp);
dh->recycleKeyPair(dKP);
}