Highlighted
Outstanding Contributor.
Outstanding Contributor.
1835 views

Read from a Portuguese identification id

Jump to solution

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.

0 Likes
2 Solutions

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Read from a Portuguese identification id

Jump to solution

testcardread.zip

I have attached a zip file containing a VS solution which contains the original C# project example and a new COBOL project example that was converted from C#. This example used an old version of the library so I had to change the reference to point to the newly installed one on my system in order to get the application to start.

Open the solution c:\testcardread\csexample\LeitorCC.sln

I have no idea if it works as I have no way to test it. When I run either version I get an exception trapped correctly so that is a start I guess.

Good luck!

View solution in original post

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Read from a Portuguese identification id

Jump to solution
Hi Chris, you're the best.

It works flawlessly.

I was just giving an error in all the instructions that had "Convert2UTF8" such as "set citizen :: Number = Convert2UTF8 (#id :: Number)".

I removed this function and stopped giving the error.
It was "set citizen :: Number = (#id :: Number)" (I think this instruction was used because of the Portuguese characters).

Anyway without this instruction it reads the Portuguese characters without any error.

Now I will adapt the solution to my application.

Thank you one more time.

Best regards
Alberto Ferraz

View solution in original post

0 Likes
14 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Read from a Portuguese identification id

Jump to solution
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.
0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Read from a Portuguese identification id

Jump to solution
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.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Read from a Portuguese identification id

Jump to solution

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.
           
0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Read from a Portuguese identification id

Jump to solution
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.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Read from a Portuguese identification id

Jump to solution

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

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Read from a Portuguese identification id

Jump to solution
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.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Read from a Portuguese identification id

Jump to solution
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.
0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Read from a Portuguese identification id

Jump to solution

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.

 

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Read from a Portuguese identification id

Jump to solution

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

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Read from a Portuguese identification id

Jump to solution
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)
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Read from a Portuguese identification id

Jump to solution
I cannot answer questions regarding this 3rd party software as I have never seen it prior to yesterday. I also do not speak Portuguese so I have no idea what is talked about in the document. All I can understand is the actual code snippets supplied but I do not actually have an understanding as to why they are being used.

What you really need to do is to reach out to the developer of this software and ask them for a complete C# example of what you are attempting to do. You can then either use the C# code as is or I can help you to convert it to COBOL.

Thanks.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.