Hi,
I have generated the key pairs using these codes
CryptokiCollection templatePub = new CryptokiCollection(); templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_PUBLIC_KEY)); templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_TOKEN, true)); templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_PRIVATE, true)); templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_LABEL, "PUKey")); templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_ID, "1")); templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_MODULUS_BITS, 1024));
CryptokiCollection templatePri = new CryptokiCollection(); templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_PRIVATE_KEY)); templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_TOKEN, true)); templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_PRIVATE, true)); templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_LABEL, "PRKey")); templatePri.Add(new ObjectAttribute(ObjectAttribute.CKA_ID, "1"));
//Generate the key pair Key[] keys = session.GenerateKeyPair(Mechanism.RSA_PKCS_KEY_PAIR_GEN, templatePub, templatePri); RSAPrivateKey privateKey = (RSAPrivateKey)keys[1]; RSAPublicKey publicKey = (RSAPublicKey)keys[0];
Now How can i export this public key to a file. ?
You should use store the properties: Modulus, PublicExponent and PrivateExponent