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


C++ CK_FUNCTION_LIST_PTR::C_GenerateKeyPair方法代码示例

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


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

示例1: testRSAPub

int testRSAPub(CK_SESSION_HANDLE hSession)
{
	CK_RV rv;
	int retVal = 0;

	CK_BBOOL ckTrue = CK_TRUE;
	CK_MECHANISM keyGenMechanism = { CKM_RSA_PKCS_KEY_PAIR_GEN, NULL_PTR, 0};
	CK_BYTE publicExponent[] = { 1, 0, 1 };
	CK_ULONG modulusBits = 1024;
	CK_MECHANISM mechanism = {
		CKM_VENDOR_DEFINED, NULL_PTR, 0
	};
	CK_OBJECT_HANDLE hPublicKey, hPrivateKey;

	CK_ATTRIBUTE publicKeyTemplate[] = {
		{ CKA_ENCRYPT, &ckTrue, sizeof(ckTrue) },
		{ CKA_VERIFY, &ckTrue, sizeof(ckTrue) },
		{ CKA_WRAP, &ckTrue, sizeof(ckTrue) },
		{ CKA_TOKEN, &ckTrue, sizeof(ckTrue) },
		{ CKA_MODULUS_BITS, &modulusBits, sizeof(modulusBits) },
		{ CKA_PUBLIC_EXPONENT, &publicExponent, sizeof(publicExponent) }
	};
	CK_ATTRIBUTE privateKeyTemplate[] = {
		{ CKA_PRIVATE, &ckTrue, sizeof(ckTrue) },
		{ CKA_SENSITIVE, &ckTrue, sizeof(ckTrue) },
		{ CKA_DECRYPT, &ckTrue, sizeof(ckTrue) },
		{ CKA_SIGN, &ckTrue, sizeof(ckTrue) },
		{ CKA_UNWRAP, &ckTrue, sizeof(ckTrue) },
		{ CKA_TOKEN, &ckTrue, sizeof(ckTrue) }
	};

	printf("\n******************************************************\n");
	printf("* Test for public information in the RSA private key *\n");
	printf("******************************************************\n\n");
	printf("You normally have a public and private key object.\n");
	printf("But the private key could contain all the necessary\n");
	printf("information in order to export the public key from the\n");
	printf("private key object. However, PKCS#11 cannot guarantee\n");
	printf("that the HSM can do this. If the private key object\n");
	printf("has all the necessary information, then you only need\n");
	printf("to keep the private key. Thus saving space in the HSM.\n\n");

	printf("Generate a key pair: ");
	rv = p11->C_GenerateKeyPair(hSession, &keyGenMechanism, publicKeyTemplate, 6, privateKeyTemplate, 6, &hPublicKey, &hPrivateKey);
	if (rv != CKR_OK)
	{
		printf("Failed to generate a keypair. rv=%s\n", rv2string(rv));
		return 1;
	}
	printf("OK\n");

	retVal = testRSAPub_keypair(hSession, hPublicKey, hPrivateKey);

	p11->C_DestroyObject(hSession, hPublicKey);
	p11->C_DestroyObject(hSession, hPrivateKey);

	return retVal;
}
开发者ID:opendnssec,项目名称:pkcs11-testing,代码行数:58,代码来源:publickey.cpp

示例2: testStability_generate

int testStability_generate(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE *hPublicKey, CK_OBJECT_HANDLE *hPrivateKey)
{
	CK_RV rv;
	CK_BBOOL ckTrue = CK_TRUE;
	CK_MECHANISM keyGenMechanism = { CKM_RSA_PKCS_KEY_PAIR_GEN, NULL_PTR, 0};
	CK_BYTE publicExponent[] = { 1, 0, 1 };
	CK_ULONG modulusBits = 1024;
	CK_MECHANISM mechanism = {
		CKM_VENDOR_DEFINED, NULL_PTR, 0
	};

	CK_ATTRIBUTE publicKeyTemplate[] = {
		{ CKA_ENCRYPT, &ckTrue, sizeof(ckTrue) },
		{ CKA_VERIFY, &ckTrue, sizeof(ckTrue) },
		{ CKA_WRAP, &ckTrue, sizeof(ckTrue) },
		{ CKA_TOKEN, &ckTrue, sizeof(ckTrue) },
		{ CKA_MODULUS_BITS, &modulusBits, sizeof(modulusBits) },
		{ CKA_PUBLIC_EXPONENT, &publicExponent, sizeof(publicExponent) }
	};
	CK_ATTRIBUTE privateKeyTemplate[] = {
		{ CKA_PRIVATE, &ckTrue, sizeof(ckTrue) },
		{ CKA_SENSITIVE, &ckTrue, sizeof(ckTrue) },
		{ CKA_DECRYPT, &ckTrue, sizeof(ckTrue) },
		{ CKA_SIGN, &ckTrue, sizeof(ckTrue) },
		{ CKA_UNWRAP, &ckTrue, sizeof(ckTrue) },
		{ CKA_TOKEN, &ckTrue, sizeof(ckTrue) }
	};

	printf("Generating a key pair...\n");
	rv = p11->C_GenerateKeyPair(hSession, &keyGenMechanism, publicKeyTemplate, 6, privateKeyTemplate, 6, hPublicKey, hPrivateKey);
	if (rv != CKR_OK)
	{
		printf("ERROR: Failed to generate a keypair. rv=%s\n", rv2string(rv));
		return 1;
	}

	return 0;
}
开发者ID:opendnssec,项目名称:pkcs11-testing,代码行数:38,代码来源:stability.cpp


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