
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SimplePIN;

import java.io.*;
import java.util.*;
import java.util.List;

/**
 *
 * @author xsvenda
 */
public class Main {

    static CardMngr cardManager = new CardMngr();
    private static byte DEFAULT_USER_PIN[] = {(byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x30};
    private static byte NEW_USER_PIN[] = {(byte) 0x31, (byte) 0x31, (byte) 0x31, (byte) 0x31};

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            if (cardManager.ConnectToCard()) {
                byte data[] = null;

                // GET PUBLIC DATA FIRST TIME
                if ((data = cardManager.GetPublicData((byte) 0, (byte) 10)) != null) {
                    System.out.println(cardManager.bytesToHex(data));
                } else {
                    System.out.println("Fail to obtain data");
                }

                // CHANGE PUBLIC DATA
                byte newData[] = new byte[2];
                newData[0] = (byte) 0x11;
                newData[1] = (byte) 0x11;
                if (cardManager.SetPublicData((byte) 0, newData)) {
                    System.out.println("Data changed");
                } else {
                    System.out.println("Fail to change data");
                }

                // GET PUBLIC DATA SECOND TIME
                if ((data = cardManager.GetPublicData((byte) 0, (byte) 10)) != null) {
                    System.out.println(cardManager.bytesToHex(data));
                } else {
                    System.out.println("Fail to obtain data");
                }


                // LOGIN TO GET ACCESS TO PRIVATE DATA
                if (cardManager.VerifyPin(DEFAULT_USER_PIN)) {
                    System.out.println("Pin verified");

                    // GET DATA TIME
                    if ((data = cardManager.GetPrivateData((byte) 0, (byte) 10)) != null) {
                        System.out.println("Private data obtained ");
                        System.out.println(cardManager.bytesToHex(data));
                    } else {
                        System.out.println("Fail to obtain private data");
                    }
                } else {
                    System.out.println("Fail to login");
                }

                cardManager.DisconnectFromCard();
            } else {
                System.out.println("Failed to connect to card");
            }
        } catch (Exception ex) {
            System.out.println("Exception : " + ex);
        }
    }
}
