Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
421 views
in Technique[技术] by (71.8m points)

pkcs#11 - How to use SafeNet Authentication Client SDK to generate RSA key pair and sign?

Is any one can provide RSA sample which use SafeNet Authentication Client SDK. The SDK only provide ECC sample. I changed something and C_GenerateKeyPair return failed. Sometimes return CKR_ATTRIBUTE_TYPE_INVALID 0x00000012. I use sample array

    /* Settings for the public key */
    CK_ATTRIBUTE tPubKey[] = 
    {
        {CKA_TOKEN,           &ck_False,        sizeof(CK_BBOOL)},
        {CKA_CLASS,           &cko_PublicKey,   sizeof(CK_ULONG)},
        {CKA_KEY_TYPE,        &ckk_RSA,         sizeof(CK_ULONG)},
        {CKA_PRIVATE,         &ck_False,        sizeof(CK_BBOOL)},
        {CKA_EC_PARAMS,       ec_params,        sizeof(ec_params)},
    };

/* Settings for the private key */
    CK_ATTRIBUTE tPrvKey[] = 
    {
        {CKA_TOKEN,           &ck_True,         sizeof(CK_BBOOL)},
        {CKA_PRIVATE,         &ck_True,         sizeof(CK_BBOOL)},
        {CKA_DERIVE,          &ck_True,             sizeof(CK_BBOOL)},
        {CKA_SIGN,            &ck_True,            sizeof(CK_BBOOL)},
    };

I change configure to RSA and I don't know what is ec_params. Actually I don't detail of template for pub. key and template for priv. key for RSA.

CK_PKCS11_FUNCTION_INFO(C_GenerateKeyPair)
#ifdef CK_NEED_ARG_LIST
(
 CK_SESSION_HANDLE    hSession,               /* session handle */
 CK_MECHANISM_PTR     pMechanism,             /* key-gen mech. */
 CK_ATTRIBUTE_PTR     pPublicKeyTemplate,          /* template for pub. key */
 CK_ULONG             ulPublicKeyAttributeCount,   /* # pub. attrs. */
 CK_ATTRIBUTE_PTR     pPrivateKeyTemplate,         /* template for priv. key */
 CK_ULONG             ulPrivateKeyAttributeCount,  /* # priv. attrs. */
 CK_OBJECT_HANDLE_PTR phPublicKey,                 /* gets pub. key handle */
 CK_OBJECT_HANDLE_PTR phPrivateKey                 /* gets priv. key handle */
 );
#endif

Can any help me this.

question from:https://stackoverflow.com/questions/65895629/how-to-use-safenet-authentication-client-sdk-to-generate-rsa-key-pair-and-sign

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have mentioned different storage classes for public and privatre parts:

    {CKA_TOKEN,           &ck_False,        sizeof(CK_BBOOL)},

and

    {CKA_TOKEN,           &ck_True,         sizeof(CK_BBOOL)},

They must have same storage class CKA_TOKEN - both must point to ck_True.

Also try without CKA_EC_PARAM.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...