Home > Net >  C # based on PC/SC with smart card communication protocol
C # based on PC/SC with smart card communication protocol

Time:01-30


I need is implemented in c #, and [37] connection in this picture, and then can send APDU commands,
I found on making danm - DE/PCSC - sharp, this is a c # access smart card based on PC/SC, but don't code comments, no CHM documents, looks good, hope to have experience can recommend this great posts or project code, thanks!

CodePudding user response:

No written, but if I had to write, I went back for the information provided by official demo and secondary development, and then in accordance with the gourd ladle do

CodePudding user response:

Smart card commonly used serial port protocol

CodePudding user response:

refer to the second floor JHDXHJ response:
smart card serial port protocol is commonly used in majority

A serial port is to and [38] communication in this picture, I can already and serial port communication, and now need to [37] communication

CodePudding user response:

Look here
https://docs.microsoft.com/zh-cn/windows/win32/api/winscard/

In general this type of operation, the first hand information is Microsoft's official API, not directly provide the class in c #, the third party packaging the most straightforward steps is to use pinvoke call c + + DLL
(winscard. DLL), so I want to know how he use, you can first take a look at c + + conventional processes, they decided to our processes (after all, the API is a c + + API, nuget can do is to simplify the call statement and objectification encapsulation, but using the process and the object definition must also compatible with c + +),

Understand this, we come to see you in to the library
https://github.com/danm-de/pcsc-sharp/blob/master/src/PCSC/Interop/Windows/WinSCardAPI.cs

 [DllImport (Unicode) WINSCARD_DLL CharSet=CharSet.] 
Private static extern int SCardEstablishContext (
[In] the int dwScope,
[In] IntPtr pvReserved1,
[In] IntPtr pvReserved2,
[In, Out] ref IntPtr phContext);

Can see he still use this way, just outside the simplified packaging is done in the

You see him first to use the demo
https://github.com/danm-de/pcsc-sharp/tree/master/Examples


Ps: from the point of view of his project, personal advice to use Reactive version of offer, I personally like considerable current version (convenient)

CodePudding user response:

A c + + API outline
https://blog.csdn.net/woshi_ziyu/article/details/7871559

Basically see this again, generally the use of the process is clear, even if the outside is a c # version of the packaging, but the basic process and the use of logic and won't have too big change

CodePudding user response:

Ps: I took a glance at each other's documentation, in fact, this documentation is written very clear

 var contextFactory=contextFactory. Instance; 
Using (var CTX=contextFactory. Establish (SCardScope. System)) {
Using (var isoReader=new isoReader (CTX, "ACME Smartcard reader", SCardShareMode. Shared, SCardProtocol. Any, false)) {
//the above 3 lines do not need to see, he was completely follow the definition of c + +, look up the connection device, as for those parameters are c + +, you see the c + + document definition is good

//the following structure a send instruction package
Var apdu=new CommandApdu (IsoCase. Case2Short, isoReader ActiveProtocol) {
CLA=0 x00,//Class
Instruction=InstructionCode GetChallenge,
P1=0 x00,//Parameter 1
The P2=0 x00,//Parameter 2
Le=0 x08//Expected length of the returned data
};
//send and get the results
Var response=isoReader. The Transmit (apdu);
Console. WriteLine (" SW1 SW2={0: X2} {1: X2} ", the response. The SW1, response. SW2);
//..
}
}


To this degree, you only need to use his good, you don't need to pipe his code comments? What this demo to annotation, this code be clear at a glance, if you want to know his under the specific implementation, I say to you don't have to go to the, it has already been said, he is actually called winscard. DLL, so his underlying process you can need not see, he was completely follows the c + + call process and define,

CodePudding user response:

refer to 6th floor wanghui0380 response:
ps: I took a glance at each other's documentation, in fact, this documentation is written very clear

 var contextFactory=contextFactory. Instance; 
Using (var CTX=contextFactory. Establish (SCardScope. System)) {
Using (var isoReader=new isoReader (CTX, "ACME Smartcard reader", SCardShareMode. Shared, SCardProtocol. Any, false)) {
//the above 3 lines do not need to see, he was completely follow the definition of c + +, look up the connection device, as for those parameters are c + +, you see the c + + document definition is good

//the following structure a send instruction package
Var apdu=new CommandApdu (IsoCase. Case2Short, isoReader ActiveProtocol) {
CLA=0 x00,//Class
Instruction=InstructionCode GetChallenge,
P1=0 x00,//Parameter 1
The P2=0 x00,//Parameter 2
Le=0 x08//Expected length of the returned data
};
//send and get the results
Var response=isoReader. The Transmit (apdu);
Console. WriteLine (" SW1 SW2={0: X2} {1: X2} ", the response. The SW1, response. SW2);
//..
}
}


To this degree, you only need to use his good, you don't need to pipe his code comments? What this demo to annotation, this code be clear at a glance, if you want to know his under the specific implementation, I say to you don't have to go to the, it has already been said, he is actually called winscard. DLL, so his underlying process you can need not see, he was completely follows the c + + call process and define,

Bosses , you're right, I just want to call the connection method and the method of command line, but I see the project file in a pile, so don't know what; The first example I folder read, thank you for your advice
  •  Tags:  
  • C#
  • Related