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


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

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


在下文中一共展示了CK_FUNCTION_LIST_PTR::C_DestroyObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: usage


//.........这里部分代码省略.........
        mask[0].pValue = key;
        mask[0].ulValueLen = key_len;

        ck_rv = epv->C_FindObjectsInit(h, mask, 1);
        if( CKR_OK != ck_rv ) {
          PR_fprintf(PR_STDERR, "C_FindObjectsInit(%lu, mask, 1) returned 0x%08x\n", 
                     h, ck_rv);
          return 1;
        }

        (void)memset(&found, 0, sizeof(found));
        nFound = 0;
        ck_rv = epv->C_FindObjects(h, found, 10, &nFound);
        if( CKR_OK != ck_rv ) {
          PR_fprintf(PR_STDERR, "C_FindObjects(%lu,, 10, ) returned 0x%08x\n", 
                     h, ck_rv);
          return 1;
        }

        if( 4 != nFound ) {
          PR_fprintf(PR_STDERR, "Found %lu objects, not 4.\n", nFound);
          return 1;
        }

        PR_fprintf(PR_STDOUT, "    Found 4 objects: %lu, %lu, %lu, %lu\n", 
                   found[0], found[1], found[2], found[3]);

        ck_rv = epv->C_FindObjectsFinal(h);
        if( CKR_OK != ck_rv ) {
          PR_fprintf(PR_STDERR, "C_FindObjectsFinal(%lu) returned 0x%08x\n", h, ck_rv);
          return 1;
        }

        ck_rv = epv->C_DestroyObject(h, hThreeIn);
        if( CKR_OK != ck_rv ) {
          PR_fprintf(PR_STDERR, "C_DestroyObject(%lu, %lu) returned 0x%08x\n", h, hThreeIn, ck_rv);
          return 1;
        }

        PR_fprintf(PR_STDOUT, "    Destroyed object three (handle = %lu)\n", hThreeIn);

        delta[0].type = CKA_APPLICATION;
        delta[0].pValue = "Changed application";
        delta[0].ulValueLen = strlen(delta[0].pValue);

        ck_rv = epv->C_SetAttributeValue(h, hTwoIn, delta, 1);
        if( CKR_OK != ck_rv ) {
          PR_fprintf(PR_STDERR, "C_SetAttributeValue(%lu, %lu, delta, 1) returned 0x%08x\n", 
                     h, hTwoIn, ck_rv);
          return 1;
        }

        PR_fprintf(PR_STDOUT, "    Changed object two (handle = %lu).\n", hTwoIn);

        /* Can another session find these session objects? */
        {
          CK_SESSION_HANDLE h2 = (CK_SESSION_HANDLE)0;

          ck_rv = epv->C_OpenSession(pSlots[i], CKF_SERIAL_SESSION, (CK_VOID_PTR)CK_NULL_PTR, (CK_NOTIFY)CK_NULL_PTR, &h2);
          if( CKR_OK != ck_rv ) {
            PR_fprintf(PR_STDERR, "C_OpenSession(%lu, CKF_SERIAL_SESSION, , ) returned 0x%08x\n", pSlots[i], ck_rv);
            return 1;
          }

          PR_fprintf(PR_STDOUT, "    Opened a second session: handle = 0x%08x\n", h2);
开发者ID:AOSC-Dev,项目名称:nss-purified,代码行数:66,代码来源:trivial.c

示例3: testStability

int testStability(CK_SLOT_ID slotID, CK_SESSION_HANDLE hSession, int rollovers, int batchjobs, int signatures, int sleepTime)
{
	CK_RV rv;
	int retVal = 0;
	CK_OBJECT_HANDLE hPublicKey, hPrivateKey;
	CK_SESSION_HANDLE hSessionTmp;
	CK_BYTE_PTR pSignature = NULL;
        CK_ULONG ulSignatureLen = 0;
	CK_BYTE pData[] = {"Text"};
	CK_ULONG ulDataLen = sizeof(pData)-1;

	printf("\n********************************************************\n");
	printf("* Test for stability during key generation and signing *\n");
	printf("********************************************************\n\n");
	printf("This test will perform the following:\n\n");
	printf("* Key rollovers = %i\n", rollovers);
	printf("  The number of times that the key pair will be replaced.\n");
	printf("* Batchjobs = %i\n", batchjobs);
	printf("  The number of batchjobs for each key pair.\n");
	printf("* signatures = %i\n", signatures);
	printf("  Each batchjob will create signatures and verify them.\n");
	printf("* sleep time = %i\n", sleepTime);
	printf("  The process will sleep between the batchjobs.\n\n");

	for (int i = 0; i <= rollovers; i++)
	{
		// Generate key pair
		if (testStability_generate(hSession, &hPublicKey, &hPrivateKey))
		{
			retVal = 1;
			continue;
		}

		for (int j = 0; j < batchjobs; j++)
		{
			// Open Session
			rv = p11->C_OpenSession(slotID, CKF_SERIAL_SESSION | CKF_RW_SESSION, NULL_PTR, NULL_PTR, &hSessionTmp);
			if (rv != CKR_OK)
			{
				printf("ERROR: Failed to open a session. rv=%s\n", rv2string(rv));
				retVal = 1;
				continue;
			}

			printf("Creating signatures and verifying them...\n");

			for (int k = 0; k < signatures; k++)
			{
				// Sign data
				if (testStability_sign(
					hSessionTmp,
					hPrivateKey,
					pData,
					ulDataLen,
					&pSignature,
					&ulSignatureLen))
				{
					retVal = 1;
					continue;
				}

				// Verify signature
				if (testStability_verify(
					hSessionTmp,
					hPublicKey,
					pData,
					ulDataLen,
					pSignature,
					ulSignatureLen))
				{
					retVal = 1;
				}

				// Clean up
				if (pSignature != NULL)
				{
					free(pSignature);
					pSignature = NULL;
					ulSignatureLen = 0;
				}
			}

			// Close session
			rv = p11->C_CloseSession(hSessionTmp);
			if (rv != CKR_OK)
			{
				printf("ERROR: Failed to close session. rv=%s\n", rv2string(rv));
				retVal = 1;
			}

			// Sleep
			printf("Sleeping for %i seconds...\n", sleepTime);
			sleep(sleepTime);
		}

		// Delete key pair
		printf("Deleting the key pair...\n");
		rv = p11->C_DestroyObject(hSession, hPublicKey);
		if (rv != CKR_OK)
		{
//.........这里部分代码省略.........
开发者ID:opendnssec,项目名称:pkcs11-testing,代码行数:101,代码来源:stability.cpp


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