Weitere ähnliche Inhalte
Kürzlich hochgeladen (20)
Apresentacao seminariotecnicocc
- 13. “ Big Picture” PCSC-lite Kernel PKCS11 CardLayer eidlib AppLayer eidgui Crypto API CSP SDK Java .Net MS Windows PKCS11 apps
- 21. Hello World C++ //***************************************************************************** // PTeID SDK sample code. // This sample demonstrates how to use the eID SDK to read a Portuguese eID card. // The program will dump the data to the standard output for each card reader // it finds. //***************************************************************************** #include <iostream> #include "eidlib.h" using namespace eIDMW; //***************************************************************************** // Get the data and dump to the screen // Beware: The data coming from the cards is encoded in UTF8! //***************************************************************************** void getEIDData( PTEID_EIDCard& card ) { PTEID_EId& eid = card.getID(); if ( card.isTestCard() ) { std::cout << "Error: This is a test card. Can not read data..." << std::endl; return; } std::cout << "DocumentType : " << eid.getDocumentType() << std::endl; std::cout << "Personal data:" << std::endl; std::cout << "FirstName : " << eid.getFirstName() << std::endl; std::cout << "Surname : " << eid.getSurname() << std::endl; std::cout << "Gender : " << eid.getGender() << std::endl; std::cout << "DateOfBirth : " << eid.getDateOfBirth() << std::endl; std::cout << "LocationOfBirth : " << eid.getLocationOfBirth() << std::endl; std::cout << "Nationality : " << eid.getNationality() << std::endl; std::cout << "NationalNumber : " << eid.getNationalNumber() << std::endl; std::cout << "MemberOfFamily : " << eid.getMemberOfFamily() << std::endl; std::cout << "ValidityBeginDate : " << eid.getValidityBeginDate() << std::endl; std::cout << "ValidityEndDate : " << eid.getValidityEndDate() << std::endl; PTEID_EIdAddress& eidaddress = card.getAddr(); std::cout << "Street : " << eidaddress.getStreet() << std::endl; std::cout << "ZipCode : " << eidaddress.getZipCode() << std::endl; std::cout << "Municipality : " << eidaddress.getMunicipality() << std::endl; std::cout << "IssuingMunicipality: " << eidaddress.getIssuingMunicipality() << std::endl; } //***************************************************************************** // Get the data from a Portuguese EID card //***************************************************************************** void getEidCardData( PTID_ReaderContext& readerContext ) { PTEID_EIDCard& card = readerContext.getEIDCard(); getEIDData(card); } //***************************************************************************** // Show the info of the card in the reader //***************************************************************************** void showCardInfo( const char* readerName ) { PTEID_ReaderContext& readerContext = ReaderSet.getReaderByName( readerName ); if ( readerContext.isCardPresent() ) { //PTEID_CARDTYPE_EID: getEidCardData( readerContext ); } } //***************************************************************************** // Show the reader info an get the data of the card if present //***************************************************************************** void showReaderCardInfo( const char* readerName ) { PTEID_ReaderContext& readerContext = ReaderSet.getReaderByName( readerName ); std::cout << "Reader: " << readerName << std::endl; std::cout << "Card present: " << (readerContext.isCardPresent()? "yes" :"no") << std::endl; showCardInfo( readerName ); std::cout << std::endl; } //***************************************************************************** // scan all the card readers and if a card is present, show the content of the // card. //***************************************************************************** void scanReaders( void ) { unsigned long nrReaders = ReaderSet.readerCount(); const char* const* readerList = ReaderSet.readerList(); std::cout << "Nr of card readers detected: " << nrReaders << std::endl; for ( size_t readerIdx=0; readerIdx<nrReaders; readerIdx++) { showReaderCardInfo( readerList[readerIdx] ); } } //***************************************************************************** // Main entry point //***************************************************************************** int main( int argc, char* argv[] ) { std::cout << "PTeID SDK C++ sample program: read_eid" << std::endl; scanReaders(); PTEID_ReleaseSDK(); }
- 22. Hello World Java //***************************************************************************** // eID SDK sample code. // This sample demonstrates how to use the eID SDK to read a Portuguese eID card. // The program will dump the data to the standard output for each card reader // it finds. // // compile: // javac -classpath <path_to>teid[35]libJava.jar main.java // // run (windows): // set PATH=<path_to_dll's>;%PATH% // java -cp <path_to>teid35libJava.jar;. main //***************************************************************************** import java.lang.*; import pt.portuguese.eid.*; public class main { //***************************************************************************** // Get the data and dump to the screen // Beware: The data coming from the cards is encoded in UTF8! //***************************************************************************** private static void getEIDData(PTEID_EIDCard card) throws Exception { PTEID_EId eid = card.getID(); System.out.println( "DocumentType : " + eid.getDocumentType() ); System.out.println( "Peronal data:" ); System.out.println( "-------------" ); System.out.println( "FirstName1 : " + eid.getFirstName1() ); System.out.println( "Surname : " + eid.getSurname() ); System.out.println( "Gender : " + eid.getGender() ); System.out.println( "DateOfBirth : " + eid.getDateOfBirth() ); System.out.println( "LocationOfBirth : " + eid.getLocationOfBirth() ); System.out.println( "Nationality : " + eid.getNationality() ); System.out.println( "NationalNumber : " + eid.getNationalNumber() ); System.out.println( "SpecialOrganization: " + eid.getSpecialOrganization() ); System.out.println( "MemberOfFamily : " + eid.getMemberOfFamily() ); System.out.println( "ValidityBeginDate : " + eid.getValidityBeginDate() ); System.out.println( "ValidityEndDate : " + eid.getValidityEndDate() ); PTEIDAddress_EId eidaddress = card.getAddr(); System.out.println( "Street : " + eid.getStreet() ); System.out.println( "ZipCode : " + eid.getZipCode() ); System.out.println( "Municipality : " + eid.getMunicipality() ); System.out.println( "Country : " + eid.getCountry() ); System.out.println( "IssuingMunicipality: " + eid.getIssuingMunicipality() ); } //***************************************************************************** // Get the data from a Portuguese EID card //***************************************************************************** private static void getEidCardData(PTEID_ReaderContext readerContext) throws Exception { PTEID_EIDCard card = readerContext.getEIDCard(); getEIDData(card); } //***************************************************************************** // Show the info of the card in the reader //***************************************************************************** private static void showCardInfo(String readerName) throws Exception { PTEID_ReaderContext readerContext = PTEID_ReaderSet.instance().getReaderByName( readerName ); if ( readerContext.isCardPresent() ) { System.out.println("Type : " + getCardTypeStr(readerContext)); PTEID_CardType cardType = readerContext.getCardType(); getEidCardData(readerContext); } } //***************************************************************************** // Show the reader info an get the data of the card if present //***************************************************************************** private static void showReaderCardInfo(String readerName) throws Exception { PTEID_ReaderContext readerContext = PTEID_ReaderSet.instance().getReaderByName( readerName ); System.out.println("Reader: "+readerName); System.out.println("Card present: " + (readerContext.isCardPresent()? "yes" :"no")); showCardInfo( readerName ); System.out.println(""); } //***************************************************************************** // scan all the card readers and if a card is present, show the content of the // card. //***************************************************************************** private static void scanReaders() throws Exception { long nrReaders = PTEID_ReaderSet.instance().readerCount(); System.out.println("Nr of card readers detected: "+nrReaders); for ( int readerIdx=0; readerIdx<nrReaders; readerIdx++) { String readerName = PTEID_ReaderSet.instance().getReaderName(readerIdx); showReaderCardInfo(readerName); } }
- 23. Hello World Java (cont.) //***************************************************************************** // Main entry point //***************************************************************************** public static void main(String argv[]) { System.out.println("[Info] PTeID SDK Java sample program: read_eid"); String osName = System.getProperty("os.name"); if ( -1 != osName.indexOf("Windows") ) { System.out.println("[Info] Windows system!!"); System.loadLibrary("beid35libJava_Wrapper"); } else { System.loadLibrary("beidlibJava_Wrapper"); } try { BEID_ReaderSet.initSDK(); scanReaders(); } catch( BEID_Exception e) { System.out.println("[Catch] BEID_Exception:" + e.GetError()); } catch( Exception e) { System.out.println("[Catch] Exception:" + e.getMessage()); } try { BEID_ReaderSet.releaseSDK(); } catch (BEID_Exception e) { System.out.println("[Catch] BEID_Exception:" + e.GetError()); } catch (Exception e) { System.out.println("[Catch] Exception:" + e.getMessage()); } } }