Read from a Portuguese identification id

Hi

I need to read the data of the Portuguese citizen's card.
It is a card with a chip that contains the citizen's data (name, address, etc).
For this there is a DLL but I can not use it because I have no experience in this type of programming.


The dll is called "pteidlib_dotnet" and is installed in ProgramFiles \ Portugal Identity Card \ sdk \ dotnet.
It is downloaded from this link:
www.autenticacao.gov.pt/.../55dd1efb-6bc9-4142-a82a-f84d1f2c0685)

According to the manual the first thing to do is to initialize the SDK.
Example given in C #

namespace PTEIDSample {
class Sample {
(...)
public static void Main (string [] args) {
PTEID_ReaderSet.initSDK ();
(...)
PTEID_ReaderSet.releaseSDK ();
}
}
}

One of the things that happens to me is that I can not use the PTEID_ReaderSet.initSDK function because it does not appear to me when I write the function.
I do not know if I lack any function or not.

To read some card data have the following in C #:

(...)
PTEID_EIDCard card = context.getEIDCard ();
PTEID_EId eid = card.getID ();
string name = eid.getGivenName ();
string nrCC = eid.getDocumentNumber ();
(...)


I think if I can start the process then I will be able to move forward. But until then...

Let's see if anyone can help me to go beyond this stage.

Thank you.

  • Have you added a reference to this assembly from within your projects references folder?
    Right-click on References and select Add Reference and then browse to where the .dll is and select it.

    Then the class and methods should be available to you.
  • Good afternoon, Chris.

    This I already did. I already added .dll to the references.

    Even so, I can not access all the .dll events.
    For example I can not access the event "initSDK" just as it is in the example I sent.

    Now I think the main problem is to create / set / initialize the variables so that I can then give the instruction to read the card.

    I have already defined a variable:
    01 X_ReaderSet type en.portugal.eid.PTEID_ReaderSet.

    I already created the statement:
    invoke X_ReaderSet :: getReader returning x_ReaderContext
    This instruction should detect which player is connected.

    When I run the program it gives the following error:
    "An unhandled exception of type 'System.NullReferenceException' occurred in pteidlib_dotnet.dll
    Additional information: The object reference was not defined as an instance of an object. "

    Thanks again.
  • Looks to me like you need to get an instance first.

    The following works for me but I get an error because I don't actually have the Reader hardware on my system:

     

          $set ilusing"pt.portugal.eid"
           program-id. Program1 as "testcardread.Program1".
    
           data division.
           working-storage section.
    	   01 X_ReaderSet type PTEID_ReaderSet value type PTEID_ReaderSet::instance.
    	   01 ReaderContext type PTEID_ReaderContext.
           procedure division.
               invoke type PTEID_ReaderSet::initSDK
               		   		   
               set ReaderContext to X_ReaderSet::getReader
    		           
    
    
               goback.
               
    
  • Now I can move forward a little bit.
    With the "set NameOfReader to X_ReaderSet :: getReader :: getName" statement I was able to access the reader name.
    The application is communicating with the reader because the led flashes when the instructions are executed.

    Now the question is to access the reader data (for example the address that is in PTEID_Address).

    I have not yet been able to write the function to fetch this data.
    I tried "set firstname to X_Address :: getStreetName" being "X_Address type PTEID_Address" but also always gives error.
    Error that gives:
    "An unhandled exception of type 'System.NullReferenceException' occurred in pteidlib_dotnet.dll
    Additional information: The object reference was not defined as an instance of an object. "

    Thank you once again for your help.
  • It looks to me like you have to drill down into the objects a bit more so that you read the StreetName obj from the Address Object which comes from the Card object etc.

    Something like this:

     

           working-storage section.
    	   01 X_ReaderSet type PTEID_ReaderSet value type PTEID_ReaderSet::instance.
    	   01 ReaderContext type PTEID_ReaderContext.
    	   01 mycard type PTEID_EIDCard.
    	   01 myAddress type PTEID_Address.
    	   01 streetname string.
           procedure division.
    
               invoke type PTEID_ReaderSet::initSDK
               set ReaderContext to X_ReaderSet::getReader
    		   set mycard to ReaderContext::getEIDCard        
    		   set myAddress to mycard::getAddr
    		   set streetname to myAddress::getStreetName
    
    
  • Hi again,

    With the instructions you sent, it does not give any compile errors but when running it gives the following error in the line "set streetname to myAddress :: getStreetName"

    An unhandled exception of type 'pt.portugal.eid.PTEID_ExParamRange' occurred in pteidlib_dotnet.dll
    Additional Information: Application Error.

    I know it's not easy not having the hardware but I ask you once again for help.
  • I am really only guessing here by using the Visual Studio Object Browser and looking thru the installed assembly so I have no idea really what these should actually be.

    Do you happen to have an example written in C# that you could post? It would be much simpler for me to convert an existing demo from C# to COBOL than it is to try to figure out how to use these classes by trial and error and not having the actual hardware to test with.
  • CC-_2D00_-Manual_5F00_de_5F00_SDK.pdf

     

    I send the manual that is available with .dll
    It is in Portuguese but has examples in C , Java and C #.

    The important thing starts in section 5.2 which is the initialization of the SDK (already done and working).

    Section 5.3 explains access to the card:

    5.3Access to the smartcard Citizen Card
    To access the Citizen Card programmatically, the following steps must be taken:
    • Obtain the list of smart card readers in the system;
    • Select a smartcard reader;
    • Verify if the player contains a card;
    • Obtain the object that provides access to the card;
    • Obtain the object containing the desired data;

    The PTEID_ReaderSet class represents the list of card readers available in the system, this class provides a variety of methods for card readers available. Through the reader list, a card reader can be selected resulting in the creation of a specific context object to the reader in question, from which it is possible to access the card.

    The reader context object provides access to the card (if present in the player). Access to the card is obtained through the PTEID_ReaderContext.getEIDCard () method that returns an object of type PTEID_EIDCard.

    Then there are the examples and C , Java and C #.

    I think that with this I may already be able to advance.

     

  • The C# example for this section f code when translated to COBOL would look something like this:

     

           working-storage section.
    	   01 myAddress type PTEID_Address.
    	   01 streetname string.
           procedure division.
    
               invoke type PTEID_ReaderSet::initSDK
               declare card as type PTEID_EIDCard
    		   declare context as type PTEID_ReaderContext
               declare readerSet as type PTEID_ReaderSet 
               set readerSet = type PTEID_ReaderSet::instance
    		   perform varying i as binary-long from 0 by 1
    		      until i >= readerSet::readerCount
                  set context = readerSet::getReaderByNum(i)
                  if context::isCardPresent
                     set card = context::getEIDCard
    		      end-if
    		   end-perform
    
    
  • Then will I have to use the variable card :: xxxxxx?
    How can I use them?

    Now check point 5.4 that is the access to the personal data of the citizen.

    5.4 Personal data of the citizen
    Citizen and card data are stored on the card in multiple files. The following fcheiros stand out:
    Identification file - contains the citizen / card data printed on the carton's faces, including the photo);
    • Address file - contains the address of the citizen, this fcheiro is conditioned access
    O citizen's certificate files - contain citizen's signature / authentication certificates.
    ◦ Certificates Files CAss.
    • Personal note file - is a free reading and writing pad where the citizen can put up to 1000 bytes.

    5.4.1.Obtaining the Identification
    To get the contents of the identifying merge, the PTEID_EIDCard.getID () method should be used.
    See examples below.

    See also sections 5.4.2 (photo) and 5.4.3 (address)