当前位置: 首页>>代码示例>>C++>>正文


C++ AsymmetricKeyPair类代码示例

本文整理汇总了C++中AsymmetricKeyPair的典型用法代码示例。如果您正苦于以下问题:C++ AsymmetricKeyPair类的具体用法?C++ AsymmetricKeyPair怎么用?C++ AsymmetricKeyPair使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AsymmetricKeyPair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void ECDSATests::testPKCS8()
{
	// Get prime256v1 domain parameters
	ECParameters* p = new ECParameters;
	p->setEC(ByteString("06082a8648ce3d030107"));

	// Generate a key-pair
	AsymmetricKeyPair* kp;

	CPPUNIT_ASSERT(ecdsa->generateKeyPair(&kp, p));
	CPPUNIT_ASSERT(kp != NULL);

	ECPrivateKey* priv = (ECPrivateKey*) kp->getPrivateKey();
	CPPUNIT_ASSERT(priv != NULL);

	// Encode and decode the private key
	ByteString pkcs8 = priv->PKCS8Encode();
	CPPUNIT_ASSERT(pkcs8.size() != 0);

	ECPrivateKey* dPriv = (ECPrivateKey*) ecdsa->newPrivateKey();
	CPPUNIT_ASSERT(dPriv != NULL);

	CPPUNIT_ASSERT(dPriv->PKCS8Decode(pkcs8));

	CPPUNIT_ASSERT(priv->getEC() == dPriv->getEC());
	CPPUNIT_ASSERT(priv->getD() == dPriv->getD());

	ecdsa->recycleParameters(p);
	ecdsa->recycleKeyPair(kp);
	ecdsa->recyclePrivateKey(dPriv);
}
开发者ID:GarysExperiments2014,项目名称:SoftHSMv2,代码行数:31,代码来源:ECDSATests.cpp

示例2:

void EDDSATests::testPKCS8()
{
	// Get ed25519 domain parameters
	ECParameters* p = new ECParameters;
	p->setEC(ByteString("06032b6570"));

	// Generate a key-pair
	AsymmetricKeyPair* kp;

	CPPUNIT_ASSERT(eddsa->generateKeyPair(&kp, p));
	CPPUNIT_ASSERT(kp != NULL);

	EDPrivateKey* priv = (EDPrivateKey*) kp->getPrivateKey();
	CPPUNIT_ASSERT(priv != NULL);

	// Encode and decode the private key
	ByteString pkcs8 = priv->PKCS8Encode();
	CPPUNIT_ASSERT(pkcs8.size() != 0);

	EDPrivateKey* dPriv = (EDPrivateKey*) eddsa->newPrivateKey();
	CPPUNIT_ASSERT(dPriv != NULL);

	CPPUNIT_ASSERT(dPriv->PKCS8Decode(pkcs8));

	CPPUNIT_ASSERT(priv->getEC() == dPriv->getEC());
	CPPUNIT_ASSERT(priv->getK() == dPriv->getK());

	eddsa->recycleParameters(p);
	eddsa->recycleKeyPair(kp);
	eddsa->recyclePrivateKey(dPriv);
}
开发者ID:jschlyter,项目名称:SoftHSMv2,代码行数:31,代码来源:EDDSATests.cpp

示例3: testKeyGeneration

void EDDSATests::testKeyGeneration()
{
	AsymmetricKeyPair* kp;

	// Curves to test
	std::vector<ByteString> curves;
	// Add x25519
	curves.push_back(ByteString("06032b656e"));
	// Add ed25519
	curves.push_back(ByteString("06032b6570"));

	for (std::vector<ByteString>::iterator c = curves.begin(); c != curves.end(); c++)
	{
		// Set domain parameters
		ECParameters* p = new ECParameters;
		p->setEC(*c);

		// Generate key-pair
		CPPUNIT_ASSERT(eddsa->generateKeyPair(&kp, p));

		EDPublicKey* pub = (EDPublicKey*) kp->getPublicKey();
		EDPrivateKey* priv = (EDPrivateKey*) kp->getPrivateKey();

		CPPUNIT_ASSERT(pub->getEC() == *c);
		CPPUNIT_ASSERT(priv->getEC() == *c);

		eddsa->recycleParameters(p);
		eddsa->recycleKeyPair(kp);
	}
}
开发者ID:jschlyter,项目名称:SoftHSMv2,代码行数:30,代码来源:EDDSATests.cpp

示例4: testKeyGeneration

void ECDSATests::testKeyGeneration()
{
	AsymmetricKeyPair* kp;

	// Curves to test
	std::vector<ByteString> curves;
	// Add X9.62 prime256v1
	curves.push_back(ByteString("06082a8648ce3d030107"));
	// Add secp384r1
	curves.push_back(ByteString("06052b81040022"));

	for (std::vector<ByteString>::iterator c = curves.begin(); c != curves.end(); c++)
	{
		// Set domain parameters
		ECParameters* p = new ECParameters;
		p->setEC(*c);

		// Generate key-pair
		CPPUNIT_ASSERT(ecdsa->generateKeyPair(&kp, p));

		ECPublicKey* pub = (ECPublicKey*) kp->getPublicKey();
		ECPrivateKey* priv = (ECPrivateKey*) kp->getPrivateKey();

		CPPUNIT_ASSERT(pub->getEC() == *c);
		CPPUNIT_ASSERT(priv->getEC() == *c);

		ecdsa->recycleParameters(p);
		ecdsa->recycleKeyPair(kp);
	}
}
开发者ID:rene-post,项目名称:SoftHSMv2,代码行数:30,代码来源:ECDSATests.cpp

示例5: CPPUNIT_ASSERT

void DSATests::testPKCS8()
{
	// Generate 1024-bit parameters for testing
	AsymmetricParameters* p;

	CPPUNIT_ASSERT(dsa->generateParameters(&p, (void*) 1024));

	// Generate a key-pair
	AsymmetricKeyPair* kp;

	CPPUNIT_ASSERT(dsa->generateKeyPair(&kp, p));
	CPPUNIT_ASSERT(kp != NULL);

	DSAPrivateKey* priv = (DSAPrivateKey*) kp->getPrivateKey();
	CPPUNIT_ASSERT(priv != NULL);

	// Encode and decode the private key
	ByteString pkcs8 = priv->PKCS8Encode();
	CPPUNIT_ASSERT(pkcs8.size() != 0);

	DSAPrivateKey* dPriv = (DSAPrivateKey*) dsa->newPrivateKey();
	CPPUNIT_ASSERT(dPriv != NULL);

	CPPUNIT_ASSERT(dPriv->PKCS8Decode(pkcs8));

	CPPUNIT_ASSERT(priv->getP() == dPriv->getP());
	CPPUNIT_ASSERT(priv->getQ() == dPriv->getQ());
	CPPUNIT_ASSERT(priv->getG() == dPriv->getG());
	CPPUNIT_ASSERT(priv->getX() == dPriv->getX());

	dsa->recycleParameters(p);
	dsa->recycleKeyPair(kp);
	dsa->recyclePrivateKey(dPriv);
}
开发者ID:bluelikeme,项目名称:SoftHSMv2,代码行数:34,代码来源:DSATests.cpp

示例6: testKeyGeneration

void GOSTTests::testKeyGeneration()
{
	AsymmetricKeyPair* kp;

	CPPUNIT_ASSERT((gost = CryptoFactory::i()->getAsymmetricAlgorithm("gost")));

	// Set domain parameters
	ByteString curve = "06072a850302022301";
	ECParameters* p = new ECParameters;
	p->setEC(curve);

	// Generate key-pair
	CPPUNIT_ASSERT(gost->generateKeyPair(&kp, p));

	GOSTPublicKey* pub = (GOSTPublicKey*) kp->getPublicKey();
	GOSTPrivateKey* priv = (GOSTPrivateKey*) kp->getPrivateKey();

	CPPUNIT_ASSERT(pub->getQ().size() == 64);
	CPPUNIT_ASSERT(priv->getD().size() == 32);

	gost->recycleParameters(p);
	gost->recycleKeyPair(kp);

	CryptoFactory::i()->recycleAsymmetricAlgorithm(gost);
	gost = NULL;
}
开发者ID:arpa2,项目名称:SoftHSMv2-with-OpenPGP,代码行数:26,代码来源:GOSTTests.cpp

示例7: testSigningVerifying

void ECDSATests::testSigningVerifying()
{
	AsymmetricKeyPair* kp;
	ECParameters *p;

	// Curves/Hashes to test
	std::vector<std::pair<ByteString, const char*> > totest;
	// Add X9.62 prime256v1
	totest.push_back(std::make_pair(ByteString("06082a8648ce3d030107"), "sha256"));
	// Add secp384r1
	totest.push_back(std::make_pair(ByteString("06052b81040022"), "sha384"));


	for (std::vector<std::pair<ByteString, const char*> >::iterator k = totest.begin(); k != totest.end(); k++)
	{
		// Get parameters
		p = new ECParameters;
		CPPUNIT_ASSERT(p != NULL);
		p->setEC(k->first);
		HashAlgorithm *hash;
		hash = CryptoFactory::i()->getHashAlgorithm(k->second);
		CPPUNIT_ASSERT(hash != NULL);

		// Generate key-pair
		CPPUNIT_ASSERT(ecdsa->generateKeyPair(&kp, p));

		// Generate some data to sign
		ByteString dataToSign;

		RNG* rng = CryptoFactory::i()->getRNG();
		CPPUNIT_ASSERT(rng != NULL);

		CPPUNIT_ASSERT(rng->generateRandom(dataToSign, 567));

		// Sign the data
		CPPUNIT_ASSERT(hash->hashInit());
		CPPUNIT_ASSERT(hash->hashUpdate(dataToSign));
		ByteString hResult;
		CPPUNIT_ASSERT(hash->hashFinal(hResult));
		ByteString sig;
		CPPUNIT_ASSERT(ecdsa->sign(kp->getPrivateKey(), hResult, sig, "ECDSA"));

		// And verify it
		CPPUNIT_ASSERT(ecdsa->verify(kp->getPublicKey(), hResult, sig, "ECDSA"));

		ecdsa->recycleKeyPair(kp);
		ecdsa->recycleParameters(p);
		CryptoFactory::i()->recycleHashAlgorithm(hash);
	}
}
开发者ID:rene-post,项目名称:SoftHSMv2,代码行数:50,代码来源:ECDSATests.cpp

示例8: testKeyGeneration

void DHTests::testKeyGeneration()
{
	AsymmetricKeyPair* kp;

	// Key sizes to test
	std::vector<size_t> keySizes;
#ifdef WITH_FIPS
	keySizes.push_back(1024);
#else
	keySizes.push_back(512);
	//keySizes.push_back(768);
	//keySizes.push_back(1024);
#endif

	for (std::vector<size_t>::iterator k = keySizes.begin(); k != keySizes.end(); k++)
	{
		// Generate parameters
		DHParameters* p;
		AsymmetricParameters** ap = (AsymmetricParameters**) &p;

		CPPUNIT_ASSERT(dh->generateParameters(ap, (void*) *k));

		// Generate key-pair
		CPPUNIT_ASSERT(dh->generateKeyPair(&kp, p));

		DHPublicKey* pub = (DHPublicKey*) kp->getPublicKey();
		DHPrivateKey* priv = (DHPrivateKey*) kp->getPrivateKey();

		CPPUNIT_ASSERT(pub->getBitLength() == *k);
		CPPUNIT_ASSERT(priv->getBitLength() == *k);

		dh->recycleKeyPair(kp);

		// Generate key-pair with a fixed private value length
		p->setXBitLength(128);
		CPPUNIT_ASSERT(dh->generateKeyPair(&kp, p));

		priv = (DHPrivateKey*) kp->getPrivateKey();

		CPPUNIT_ASSERT(priv->getX().bits() == 128);

		dh->recycleParameters(p);
		dh->recycleKeyPair(kp);
	}
}
开发者ID:bluelikeme,项目名称:SoftHSMv2,代码行数:45,代码来源:DHTests.cpp

示例9: testKeyGeneration

void RSATests::testKeyGeneration()
{
	AsymmetricKeyPair* kp;
	RSAParameters p;

	// Public exponents to test
	std::vector<ByteString> exponents;
	exponents.push_back("010001");
	exponents.push_back("03");
	exponents.push_back("0B");
	exponents.push_back("11");

	// Key sizes to test
	std::vector<size_t> keySizes;
	keySizes.push_back(1024);
#ifndef WITH_FIPS
	keySizes.push_back(1025);
#endif
	keySizes.push_back(1280);
	keySizes.push_back(2048);
	//keySizes.push_back(4096);

	for (std::vector<ByteString>::iterator e = exponents.begin(); e != exponents.end(); e++)
	{
		for (std::vector<size_t>::iterator k = keySizes.begin(); k != keySizes.end(); k++)
		{
			p.setE(*e);
			p.setBitLength(*k);

			// Generate key-pair
			CPPUNIT_ASSERT(rsa->generateKeyPair(&kp, &p));

			RSAPublicKey* pub = (RSAPublicKey*) kp->getPublicKey();
			RSAPrivateKey* priv = (RSAPrivateKey*) kp->getPrivateKey();

			CPPUNIT_ASSERT(pub->getBitLength() == *k);
			CPPUNIT_ASSERT(priv->getBitLength() == *k);
			CPPUNIT_ASSERT(pub->getE() == *e);
			CPPUNIT_ASSERT(priv->getE() == *e);

			rsa->recycleKeyPair(kp);
		}
	}
}
开发者ID:bellgrim,项目名称:SoftHSMv2,代码行数:44,代码来源:RSATests.cpp

示例10: CPPUNIT_ASSERT

void DHTests::testPKCS8()
{
	// Generate 1024-bit parameters for testing
	AsymmetricParameters* p;

	//CPPUNIT_ASSERT(dh->generateParameters(&p, (void*) 1024));
	// changed for 512-bit for speed...
#ifndef WITH_BOTAN
	CPPUNIT_ASSERT(dh->generateParameters(&p, (void*) 1024));
#else
	CPPUNIT_ASSERT(dh->generateParameters(&p, (void*) 512));
#endif

	// Generate a key-pair
	AsymmetricKeyPair* kp;

	CPPUNIT_ASSERT(dh->generateKeyPair(&kp, p));
	CPPUNIT_ASSERT(kp != NULL);

	DHPrivateKey* priv = (DHPrivateKey*) kp->getPrivateKey();
	CPPUNIT_ASSERT(priv != NULL);

	// Encode and decode the private key
	ByteString pkcs8 = priv->PKCS8Encode();
	CPPUNIT_ASSERT(pkcs8.size() != 0);

	DHPrivateKey* dPriv = (DHPrivateKey*) dh->newPrivateKey();
	CPPUNIT_ASSERT(dPriv != NULL);

	CPPUNIT_ASSERT(dPriv->PKCS8Decode(pkcs8));


	CPPUNIT_ASSERT(priv->getP() == dPriv->getP());
	CPPUNIT_ASSERT(priv->getG() == dPriv->getG());
	CPPUNIT_ASSERT(priv->getX() == dPriv->getX());

	dh->recycleParameters(p);
	dh->recycleKeyPair(kp);
	dh->recyclePrivateKey(dPriv);
}
开发者ID:bluelikeme,项目名称:SoftHSMv2,代码行数:40,代码来源:DHTests.cpp

示例11: testSigningVerifying

void EDDSATests::testSigningVerifying()
{
	AsymmetricKeyPair* kp;
	ECParameters *p;

	// Curves to test
	std::vector<ByteString> curves;
	// Add ed25519
	curves.push_back(ByteString("06032b6570"));

	for (std::vector<ByteString>::iterator c = curves.begin(); c != curves.end(); c++)
	{
		// Get parameters
		p = new ECParameters;
		CPPUNIT_ASSERT(p != NULL);
		p->setEC(*c);

		// Generate key-pair
		CPPUNIT_ASSERT(eddsa->generateKeyPair(&kp, p));

		// Generate some data to sign
		ByteString dataToSign;

		RNG* rng = CryptoFactory::i()->getRNG();
		CPPUNIT_ASSERT(rng != NULL);

		CPPUNIT_ASSERT(rng->generateRandom(dataToSign, 567));

		// Sign the data
		ByteString sig;
		CPPUNIT_ASSERT(eddsa->sign(kp->getPrivateKey(), dataToSign, sig, AsymMech::EDDSA));

		// And verify it
		CPPUNIT_ASSERT(eddsa->verify(kp->getPublicKey(), dataToSign, sig, AsymMech::EDDSA));

		eddsa->recycleKeyPair(kp);
		eddsa->recycleParameters(p);
	}
}
开发者ID:jschlyter,项目名称:SoftHSMv2,代码行数:39,代码来源:EDDSATests.cpp

示例12: testKeyGeneration

void DSATests::testKeyGeneration()
{
	AsymmetricKeyPair* kp;

	// Key sizes to test
	std::vector<size_t> keySizes;
#ifndef WITH_FIPS
	keySizes.push_back(512);
	keySizes.push_back(768);
	keySizes.push_back(1024);
	keySizes.push_back(1536);
#else
	keySizes.push_back(1024);
#endif
#ifndef WITH_BOTAN
	keySizes.push_back(2048);
#endif

	for (std::vector<size_t>::iterator k = keySizes.begin(); k != keySizes.end(); k++)
	{
		// Generate parameters
		DSAParameters* p;
		AsymmetricParameters** ap = (AsymmetricParameters**) &p;

		CPPUNIT_ASSERT(dsa->generateParameters(ap, (void*) *k));

		// Generate key-pair
		CPPUNIT_ASSERT(dsa->generateKeyPair(&kp, p));

		DSAPublicKey* pub = (DSAPublicKey*) kp->getPublicKey();
		DSAPrivateKey* priv = (DSAPrivateKey*) kp->getPrivateKey();

		CPPUNIT_ASSERT(pub->getBitLength() == *k);
		CPPUNIT_ASSERT(priv->getBitLength() == *k);

		dsa->recycleParameters(p);
		dsa->recycleKeyPair(kp);
	}
}
开发者ID:bluelikeme,项目名称:SoftHSMv2,代码行数:39,代码来源:DSATests.cpp

示例13: CPPUNIT_ASSERT

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;
}
开发者ID:arpa2,项目名称:SoftHSMv2-with-OpenPGP,代码行数:53,代码来源:GOSTTests.cpp

示例14: testSigningVerifying

void GOSTTests::testSigningVerifying()
{
	AsymmetricKeyPair* kp;
	ECParameters *p;
	ByteString curve = "06072a850302022301";

	CPPUNIT_ASSERT((gost = CryptoFactory::i()->getAsymmetricAlgorithm("gost")));

	// Get parameters
	p = new ECParameters;
	CPPUNIT_ASSERT(p != NULL);
	p->setEC(curve);

	// Generate key-pair
	CPPUNIT_ASSERT(gost->generateKeyPair(&kp, p));

	// Generate some data to sign
	ByteString dataToSign;

	RNG* rng = CryptoFactory::i()->getRNG();
	CPPUNIT_ASSERT(rng != NULL);

	CPPUNIT_ASSERT(rng->generateRandom(dataToSign, 567));

	// Sign the data
	ByteString sig;
	CPPUNIT_ASSERT(gost->sign(kp->getPrivateKey(), dataToSign, sig, "gost-gost"));

	// And verify it
	CPPUNIT_ASSERT(gost->verify(kp->getPublicKey(), dataToSign, sig, "gost-gost"));

	gost->recycleKeyPair(kp);
	gost->recycleParameters(p);

	CryptoFactory::i()->recycleAsymmetricAlgorithm(gost);
	gost = NULL;
}
开发者ID:arpa2,项目名称:SoftHSMv2-with-OpenPGP,代码行数:37,代码来源:GOSTTests.cpp

示例15: CPPUNIT_ASSERT

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);
}
开发者ID:rene-post,项目名称:SoftHSMv2,代码行数:51,代码来源:ECDSATests.cpp


注:本文中的AsymmetricKeyPair类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。