Ejemplo n.º 1
0
        public static byte[] ReadFile(byte[] fileID, byte pinId)
        {
            PTEID_ByteArray pb = new PTEID_ByteArray();

            byte[]    retArray = null;
            PTEID_Pin pin      = null;

            if (readerContext != null)
            {
                try {
                    if (pinId != 0)
                    {
                        PTEID_Pins pins = idCard.getPins();
                        for (uint pinIdx = 0; pinIdx < pins.count(); pinIdx++)
                        {
                            pin = (pins.getPinByNumber(pinIdx));
                            if (pin.getPinRef() == pinId)
                            {
                                break;
                            }
                        }
                    }

                    idCard.readFile(ashex(fileID), pb, pin);

                    int trimmedSize = trimStart(pb.GetBytes());
                    if ((trimmedSize == 0) && (pb.Size() > 0))
                    {
                        trimmedSize = (int)pb.Size();
                    }

                    retArray = new byte[trimmedSize];
                    Array.Copy(pb.GetBytes(), 0, retArray, 0, retArray.Length);
                }
                catch (PTEID_Exception ex)
                {
                    handleUnderlyingException(ex);
                }
            }
            return(retArray);
        }
Ejemplo n.º 2
0
        public static PteidCertif[] GetCertificates()
        {
            PteidCertif[]   certs = null;
            PTEID_ByteArray ba    = new PTEID_ByteArray();

            try {
                PTEID_Certificates certificates = idCard.getCertificates();
                certs = new PteidCertif[(int)certificates.countAll()];
                for (uint i = 0; i < certs.Length; i++)
                {
                    certs[i] = new PteidCertif();
                    certificates.getCert(i).getFormattedData(ba);
                    certs[i].certif = new byte[(int)(ba.Size())];
                    Array.Copy(ba.GetBytes(), 0, certs[i].certif, 0, (int)ba.Size());
                    certs[i].certifLabel = certificates.getCert(i).getLabel();
                }
            }
            catch (PTEID_Exception ex)
            {
                throw new PteidException(ex.GetError());
            }

            return(certs);
        }
Ejemplo n.º 3
0
        public static byte[] CVC_ReadFile(byte[] fileID)
        {
            byte[] ret = null;

            PTEID_ByteArray ba_fileID = new PTEID_ByteArray(fileID, (uint)fileID.Length);

            //TODO: Make the Exception retro-compatible
            try
            {
                PTEID_ByteArray ba = pteidlib_dotNet.PTEID_CVC_ReadFile(ba_fileID);
                ret = new byte[(int)ba.Size()];
                Array.Copy(ba.GetBytes(), ret, ret.Length);
            }
            catch (PTEID_Exception ex)
            {
                throw new PteidException(ex.GetError());
            }
            return(ret);
        }
Ejemplo n.º 4
0
        public static byte[] CVC_Init(byte[] cvc_cert)
        {
            byte[] ret = null;

            PTEID_ByteArray cvc = new PTEID_ByteArray(cvc_cert, (uint)cvc_cert.Length);

            //Make the Exception retro-compatible
            try
            {
                PTEID_ByteArray ba = pteidlib_dotNet.PTEID_CVC_Init(cvc);
                ret = new byte[(int)ba.Size()];
                Array.Copy(ba.GetBytes(), ret, ret.Length);
            }
            catch (PTEID_Exception ex)
            {
                throw new PteidException(ex.GetError());
            }

            return(ret);
        }
Ejemplo n.º 5
0
        /*
         * Saves the card's holder photo in PNG format
         */
        public void SavePhoto(String output_file)
        {
            //Gets the object representing the photograph present in the card
            PTEID_Photo photoObj = eid.getPhotoObj();

            //Gets the bytes of the photo in JPEG2000 format
            PTEID_ByteArray praw = photoObj.getphotoRAW();

            //Gets the bytes of the photo in PNG format
            PTEID_ByteArray ppng = photoObj.getphoto();

            Console.WriteLine("Size of PhotoObj:       " + photoObj.getphotoImageinfo().Size());
            Console.WriteLine("Size of JPEG2000:       " + praw.Size());
            Console.WriteLine("Size of PNG:            " + ppng.Size());

            //Saves the PNG format photo, with the name specified by the user
            MemoryStream memoryStream = new MemoryStream(ppng.GetBytes());
            Image        img          = Image.FromStream(memoryStream);

            img.Save("../../files/" + output_file);

            Console.WriteLine("Image was successfuly saved at target location.");
        }
Ejemplo n.º 6
0
    public static PTEID_Certif[] GetCertificates(){
        PTEID_Certif[] certs = null;
        PTEID_ByteArray ba = new PTEID_ByteArray();
        
        try {
            PTEID_Certificates certificates = idCard.getCertificates();
            certs = new PTEID_Certif[(int)certificates.countAll()];
            for(uint i=0;i<certs.Length;i++){
                certs[i] = new PTEID_Certif();
                certificates.getCert(i).getFormattedData(ba);
                certs[i].certif = new byte[(int)(ba.Size())];
                Array.Copy(ba.GetBytes(), 0, certs[i].certif, 0, (int)ba.Size());
                certs[i].certifLabel = certificates.getCert(i).getLabel();
            }
        } catch (Exception ex) {
            throw new PteidException(0);
        }

        return certs;
    }