public void Run() { try { ConsoleWriter.Instance.PrintSplitter(); ConsoleWriter.Instance.PrintTask("Establishing SAM Secure Session"); var reader = new SmartCardReader(_readerName); using (var secureSession = new SamSecureSession(reader)) { secureSession.Establish(SamSecureSessionMasterKey, SamSecureSessionKeyNumber); if (secureSession.IsSessionActive) { ConsoleWriter.Instance.PrintMessage("Session established"); ExecuteExample(secureSession); ConsoleWriter.Instance.PrintSplitter(); } else { ConsoleWriter.Instance.PrintError("Failed to establish session"); } } } catch (Exception e) { ConsoleWriter.Instance.PrintError("Exception's been thrown: message = " + e.Message); } }
protected override void ExecuteExample(SamSecureSession session) { SendAuthNativeCommand(session, 0x00, "030101"); SendCreateApplicationCommand(session, "010208", 0x0f, 0x07); SendSelectApplicationCommand(session, "010208"); SendCreateStandardDataFileCommand(session, 0x00, SEPCommand.CommunicationMode.Plain, "00EEEE", "000100"); SendWriteDataCommand(session, 0x00, "00", "00112233445566778899AABBCCDDEEFF", SEPCommand.CommunicationMode.Plain, SEPCommand.CommitFlag.NoCommit); SendReadDataCommand(session, 0x00, "00", 0x10, SEPCommand.CommunicationMode.Plain); }
protected void SendAuthNativeCommand(SamSecureSession session, byte keyNumber, string keyReference) { var command = new SEPDESFireAuthNative(); var input = command.GetApdu(keyNumber, keyReference); var output = session.SendCommand(input); var response = command.TranslateResponse(output); PrintCommand("Auth Native", input, output, response); }
private void SendSelectApplicationCommand(SamSecureSession session, string applicationNumber) { var command = new SEPDESFireSelectApplication(); var input = command.GetApdu(applicationNumber); var output = session.SendCommand(input); var response = command.TranslateResponse(output); PrintCommand("Select Application", input, output, response); }
private void SendCreateApplicationCommand(SamSecureSession session, string applicationNumber, byte masterKeySettings, byte numberOfKeys) { var command = new SEPDESFireCreateApplication(); var input = command.GetApdu(applicationNumber, masterKeySettings, numberOfKeys); var output = session.SendCommand(input); var response = command.TranslateResponse(output); PrintCommand("Create Application", input, output, response); }
private void SendFormatCardCommand(SamSecureSession session) { var command = new SEPDESFireFormatCard(); var input = command.GetApdu(); var output = session.SendCommand(input); var response = command.TranslateResponse(output); PrintCommand("Format Card", input, output, response); }
private void SendLoadKeyCommand(SamSecureSession session, SEPLoadKey.Persistence persistence, string keyReference, string keyValue) { var command = new SEPLoadKey(); var input = command.GetApdu(persistence, keyReference, keyValue); var output = session.SendCommand(input); var response = command.TranslateResponse(output); PrintCommand("Load Key", input, output, response); }
private void SendReadPACSDataCommand(SamSecureSession session) { var command = new SEPReadPACSData(); var input = command.GetApdu(); var output = session.SendCommand(input); var response = command.TranslateResponse(output); PrintCommand("Read PACS Data", input, output, response); PrintDetailedResponse(response); }
private void SendReadDataCommand(SamSecureSession session, byte fileNumber, string offset, byte numberOfBytesToBeRead, SEPCommand.CommunicationMode communicationMode) { var command = new SEPDESFireReadData(); var input = command.GetApdu(fileNumber, offset, numberOfBytesToBeRead, communicationMode); var output = session.SendCommand(input); var response = command.TranslateResponse(output); PrintCommand("Read Data", input, output, response); PrintDetailedResponse(response); }
private void SendWriteDataCommand(SamSecureSession session, byte fileNumber, string offset, string dataToBeWritten, SEPCommand.CommunicationMode communicationMode, SEPCommand.CommitFlag commitFlag) { var command = new SEPDESFireWriteData(); var input = command.GetApdu(fileNumber, offset, dataToBeWritten, communicationMode, commitFlag); var output = session.SendCommand(input); var response = command.TranslateResponse(output); PrintCommand("Write Data", input, output, response); }
private void SendCreateStandardDataFileCommand(SamSecureSession session, byte fileNumber, SEPCommand.CommunicationMode communicationMode, string accessRights, string fileSize) { var command = new SEPDESFireCreateStandardDataFile(); var input = command.GetApdu(fileNumber, communicationMode, accessRights, fileSize); var output = session.SendCommand(input); var response = command.TranslateResponse(output); PrintCommand("Create Standard Data File", input, output, response); }
protected abstract void ExecuteExample(SamSecureSession session);
protected override void ExecuteExample(SamSecureSession session) { SendReadPACSDataCommand(session); }
protected override void ExecuteExample(SamSecureSession session) { SendAuthNativeCommand(session, 0x00, "030101"); SendFormatCardCommand(session); }
protected override void ExecuteExample(SamSecureSession session) { SendLoadKeyCommand(session, SEPLoadKey.Persistence.Persistent, "030101", "00000000000000000000000000000000"); SendLoadKeyCommand(session, SEPLoadKey.Persistence.Persistent, "030102", "101112131415161718191a1b1c1d1e1f"); }