static void WriteCardDataObjects() { DataObjectStore dataObjectStore = RestoreDataObjects(); PKCS11.Initialize("etoken.dll"); PKCS11.Slot[] slots = PKCS11.GetSlotList(true); if (slots.Length > 0) { PKCS11.Slot slot = slots[0]; PKCS11.Session session = PKCS11.OpenSession(slot, PKCS11.CKF_RW_SESSION | PKCS11.CKF_SERIAL_SESSION); int loginResult = session.Login(PKCS11.CKU_USER, null); if (loginResult == PKCS11.CKR_OK || loginResult == PKCS11.CKR_USER_ALREADY_LOGGED_IN) { Console.WriteLine("PIN was correct"); Console.WriteLine("\nWriting Data Objects"); Console.WriteLine("------------------------------------------------------------"); foreach (DataObject dataObject in dataObjectStore.objects) { PKCS11.Attribute[] newDataObject = new PKCS11.Attribute[] { new PKCS11.Attribute(PKCS11.CKA_CLASS, dataObject.cka_class), new PKCS11.Attribute(PKCS11.CKA_TOKEN, dataObject.cka_token), new PKCS11.Attribute(PKCS11.CKA_PRIVATE, dataObject.cka_private), new PKCS11.Attribute(PKCS11.CKA_LABEL, dataObject.cka_label), new PKCS11.Attribute(PKCS11.CKA_APPLICATION, dataObject.cka_application), new PKCS11.Attribute(PKCS11.CKA_VALUE, StringToByteArray(dataObject.cka_value)), }; PKCS11.Object.Create(session, newDataObject); Console.WriteLine(dataObject.cka_label + ": " + (dataObject.cka_value.Length >= 40 ? dataObject.cka_value.Substring(0, 40) + "..." : dataObject.cka_value)); } } else { Console.WriteLine("PIN was not correct"); } session.Close(); PKCS11.Finalize(); } else { Console.WriteLine("Please connect a token and try again."); } }
static void WriteCardDataObjects() { DataObjectStore dataObjectStore = RestoreDataObjects(); PKCS11.Initialize("etoken.dll"); PKCS11.Slot[] slots = PKCS11.GetSlotList(true); if (slots.Length > 0) { PKCS11.Slot slot = slots[0]; PKCS11.Session session = PKCS11.OpenSession(slot, PKCS11.CKF_RW_SESSION | PKCS11.CKF_SERIAL_SESSION); int loginResult = session.Login(PKCS11.CKU_USER, null); if (loginResult == PKCS11.CKR_OK || loginResult == PKCS11.CKR_USER_ALREADY_LOGGED_IN) { Console.WriteLine("PIN was correct"); Console.WriteLine("\nWriting Data Objects"); Console.WriteLine("------------------------------------------------------------"); foreach (DataObject dataObject in dataObjectStore.objects) { PKCS11.Attribute[] newDataObject = new PKCS11.Attribute[] { new PKCS11.Attribute(PKCS11.CKA_CLASS, dataObject.cka_class), new PKCS11.Attribute(PKCS11.CKA_TOKEN, dataObject.cka_token), new PKCS11.Attribute(PKCS11.CKA_PRIVATE, dataObject.cka_private), new PKCS11.Attribute(PKCS11.CKA_LABEL, dataObject.cka_label), new PKCS11.Attribute(PKCS11.CKA_APPLICATION, dataObject.cka_application), new PKCS11.Attribute(PKCS11.CKA_VALUE, StringToByteArray(dataObject.cka_value)), }; PKCS11.Object.Create(session, newDataObject); Console.WriteLine(dataObject.cka_label + ": " + (dataObject.cka_value.Length >= 40 ? dataObject.cka_value.Substring(0, 40) + "..." : dataObject.cka_value)); } } else { Console.WriteLine("PIN was not correct"); } session.Close(); PKCS11.Finalize(); } else { Console.WriteLine("Please connect a token and try again."); } }