Issue While generating Keypair

6/20/2019 9:12:57 AM
Total Posts 2

Issue While generating Keypair

Hi team ,

    I am trying to generate the GenerateKeyPair but  I am getting the error "Error n. 6"  and FUNCTION_FAILED as error String . could you please help on this following are my code


                CryptokiCollection templatePub = new CryptokiCollection();            

                templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS,  


              templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_TOKEN, true));

               templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_PRIVATE, false));    

            templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_LABEL, "Ugo's new Key"));     

           templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_ID, "1"));

               templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_MODULUS_BITS, 1024));

               templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_PUBLIC_EXPONENT, 0x010001));  

              // Prepares the templates for private key  

              CryptokiCollection templatePri = new CryptokiCollection();  

              templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS,


            templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_TOKEN, true));   

            templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_PRIVATE, true));

               templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_LABEL, "Ugo's new Key"));   

             templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_ID, "1"));  

              //generate the key pair objects              

            Key[] keys = session.GenerateKeyPair(Mechanism.RSA_PKCS_KEY_PAIR_GEN, templatePub, templatePri);  /// getting error here

6/21/2019 3:33:06 PM
Total Posts 300
Ugo Chirico

Re: Issue While generating Keypair

Usually, each HSM needs its own parameters to generate a key pair.

Maybe in your code you set a parameter not recognized by the HSM. See in the documentation of your HSM which are the parameters you have to set.