コード例 #1
0
ファイル: Pteid.cs プロジェクト: sergiomb2/ccidadao
        public static void WriteFileInOffset(byte[] file, byte[] data, byte pinId, int offset)
        {
            PTEID_ByteArray pb  = new PTEID_ByteArray(data, (uint)data.Length);
            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;
                            }
                        }
                    }

                    bool ret = idCard.writeFile(ashex(file), pb, pin, "", (uint)offset);
                }
                catch (PTEID_Exception ex)
                {
                    handleUnderlyingException(ex);
                }
            }
        }
コード例 #2
0
ファイル: Pteid.cs プロジェクト: sergiomb2/ccidadao
        public static void CVC_Authenticate(byte[] signedChallenge)
        {
            PTEID_ByteArray signed_challenge = new PTEID_ByteArray(signedChallenge, (uint)signedChallenge.Length);

            try
            {
                pteidlib_dotNet.PTEID_CVC_Authenticate(signed_challenge);
            }
            catch (PTEID_Exception ex)
            {
                throw new PteidException(ex.GetError());
            }
        }
コード例 #3
0
        /*
         * Writes notes to the card (needs authentication pin)
         */
        public void WriteNotes()
        {
            //Prepares a string (notes) to be written in the card
            String notes = "We wrote successfully to the card!";

            byte[]          notesBytes    = Encoding.UTF8.GetBytes(notes);
            PTEID_ByteArray personalNotes = new PTEID_ByteArray(notesBytes, (uint)notesBytes.Length);
            Boolean         ok;

            //Gets authentication pin
            PTEID_Pins pins = eidCard.getPins();
            PTEID_Pin  pin  = pins.getPinByPinRef(PTEID_Pin.AUTH_PIN);

            //Writes notes to card
            ok = eidCard.writePersonalNotes(personalNotes, pin);
            Console.WriteLine("Was writing successful? " + (ok? "Yes!" : "No."));
        }
コード例 #4
0
ファイル: Pteid.cs プロジェクト: sergiomb2/ccidadao
        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);
        }
コード例 #5
0
ファイル: Pteid.cs プロジェクト: sergiomb2/ccidadao
        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);
        }
コード例 #6
0
ファイル: Pteid.cs プロジェクト: sergiomb2/ccidadao
 public static void SelectADF(byte[] bytes)
 {
     if (readerContext != null)
     {
         try {
             byte[]          ap   = { 0x00, (byte)0xA4, 0x00, 0x0C };
             PTEID_ByteArray apdu = new PTEID_ByteArray(ap, (uint)ap.Length);
             byte[]          temp = new byte[1];
             temp[0] = (byte)bytes.Length;
             apdu.Append(temp, 1);
             apdu.Append(bytes, (uint)bytes.Length);
             PTEID_ByteArray apdu_result = idCard.sendAPDU(apdu);
             //TODO: check return code ?
         }
         catch (PTEID_Exception ex)
         {
             throw new PteidException(ex.GetError());
         }
     }
 }
コード例 #7
0
ファイル: Pteid.cs プロジェクト: sergiomb2/ccidadao
        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);
        }
コード例 #8
0
ファイル: Pteid.cs プロジェクト: sergiomb2/ccidadao
        public static byte[] ReadSOD()
        {
            byte[] sod = null;

            if (readerContext != null)
            {
                try {
                    PTEID_ByteArray pba = idCard.getSod().getData();

                    int trimmedSize = trimStart(pba.GetBytes());

                    sod = new byte[trimmedSize];
                    Array.Copy(pba.GetBytes(), 0, sod, 0, sod.Length);
                }
                catch (PTEID_Exception ex)
                {
                    throw new PteidException(ex.GetError());
                }
            }
            return(sod);
        }
コード例 #9
0
ファイル: Pteid.cs プロジェクト: sergiomb2/ccidadao
        public static byte[] SendAPDU(byte[] bytes)
        {
            byte[] ret = null;
            if (readerContext != null)
            {
                try {
                    PTEID_ByteArray sApdu = new PTEID_ByteArray(bytes, (uint)bytes.Length);
                    PTEID_ByteArray resp;

                    resp = idCard.sendAPDU(sApdu);

                    ret = new byte[(int)resp.Size()];
                    Array.Copy(resp.GetBytes(), 0, ret, 0, ret.Length);
                }
                catch (PTEID_Exception ex)
                {
                    throw new PteidException(ex.GetError());
                }
            }

            return(ret);
        }
コード例 #10
0
ファイル: Pteid.cs プロジェクト: sergiomb2/ccidadao
        public static void Activate(String actPin, byte[] bytes, uint activateMode)
        {
            PTEID_ByteArray pb = new PTEID_ByteArray(bytes, (uint)bytes.Length);

            if (readerContext != null)
            {
                try {
                    bool mode = activateMode == MODE_ACTIVATE_BLOCK_PIN;
                    idCard.Activate(actPin, pb, mode);
                }
                catch (PTEID_Exception ex) {
                    if (ex.GetError() == pteidlib_dotNet.EIDMW_ERR_PIN_CANCEL)
                    {
                        throw new PteidException(SC_ERROR_PIN_CODE_INCORRECT);
                    }
                    else
                    {
                        throw new PteidException(ex.GetError());
                    }
                }
            }
        }
コード例 #11
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.");
        }
コード例 #12
0
ファイル: Pteid.cs プロジェクト: sergiomb2/ccidadao
        public static void SetSODCAs(PteidCertif[] certificates)
        {
            if (readerContext != null)
            {
                try
                {
                    if (null == certificates)
                    {
                        readerContext.getEIDCard().getCertificates().resetSODCAs();
                        return;
                    }

                    foreach (PteidCertif pcert in certificates)
                    {
                        PTEID_ByteArray pba = new PTEID_ByteArray(pcert.certif, (uint)pcert.certif.Length);
                        readerContext.getEIDCard().getCertificates().addToSODCAs(pba);
                    }
                }
                catch (PTEID_Exception ex)
                {
                    throw new PteidException(ex.GetError());
                }
            }
        }
コード例 #13
0
ファイル: Pteid.cs プロジェクト: sergiomb2/ccidadao
        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);
        }
コード例 #14
0
ファイル: Pteid.cs プロジェクト: 12019/svn.gov.pt
 public static void SetSODCAs(PTEID_Certif[] pteidcs){
     if (readerContext != null) {
         try {
             foreach (PTEID_Certif pcert in  pteidcs) {
                 PTEID_ByteArray pba = new PTEID_ByteArray(pcert.certif, (uint)pcert.certif.Length);
                 readerContext.getEIDCard().getCertificates().addCertificate(pba);
             }
         } catch (Exception ex) {
             throw new PteidException(0);
         }
     }
 }
コード例 #15
0
ファイル: Pteid.cs プロジェクト: 12019/svn.gov.pt
    public static byte[] SendAPDU(byte[] bytes) {
        byte[] ret = null;
        if (readerContext != null) {
            try {
                PTEID_ByteArray sApdu = new PTEID_ByteArray(bytes, (uint)bytes.Length);
                PTEID_ByteArray resp;

                resp = idCard.sendAPDU(sApdu);

                ret = new byte[(int) resp.Size()];
                Array.Copy(resp.GetBytes(), 0, ret, 0, ret.Length);
            } catch (Exception) {
            }
        }
        
        return ret;
    }
コード例 #16
0
ファイル: Pteid.cs プロジェクト: 12019/svn.gov.pt
 public static void Activate(String actPin, byte[] bytes, int i){
     PTEID_ByteArray pb = new PTEID_ByteArray(bytes, (uint)bytes.Length);
     if (readerContext != null) {
         try {
             idCard.Activate(actPin, pb);
         } catch (Exception ex) {
             throw new PteidException(0);
         }
     }
 }
コード例 #17
0
ファイル: Pteid.cs プロジェクト: 12019/svn.gov.pt
    public static void WriteFile(byte[] file, byte[] data, byte pinId){
        PTEID_ByteArray pb = new PTEID_ByteArray(data, (uint)data.Length);
        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() == PTEID_ADDRESS_PIN)
                            break;
                    }
                }

                idCard.writeFile(ashex(file),pb,pin);
                
            } catch (Exception ex) {
                throw new PteidException(0);
            }
        }
    }
コード例 #18
0
ファイル: Pteid.cs プロジェクト: 12019/svn.gov.pt
    public static byte[] ReadFile(byte[] bytes, 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() == PTEID_ADDRESS_PIN)
                            break;
                    }
                }

                idCard.readFile(ashex(bytes), pb, pin);
                  
                int trimmedSize = trimStart(pb.GetBytes());
               
                retArray = new byte[trimmedSize];
                Array.Copy(pb.GetBytes(), 0, retArray, 0, retArray.Length);
            } catch (Exception ex) {
                throw new PteidException(0);
            }
        }
        return retArray;
    }
コード例 #19
0
ファイル: Pteid.cs プロジェクト: 12019/svn.gov.pt
 public static void SelectADF(byte[] bytes){
     if (readerContext != null) {
         try {
             byte[] ap = {0x00, (byte) 0xA4, 0x00, 0x0C};
             PTEID_ByteArray apdu = new PTEID_ByteArray(ap, (uint)ap.Length);
             byte[] temp = new byte[1];
             temp[0] = (byte) bytes.Length;
             apdu.Append(temp, 1);
             apdu.Append(bytes, (uint)bytes.Length);
             PTEID_ByteArray sendAPDU = idCard.sendAPDU(apdu);
             //verificar se correu tudo bem... ?
         } catch (Exception ex) {
             throw new PteidException(0);
         }
     }
 }
コード例 #20
0
ファイル: Pteid.cs プロジェクト: 12019/svn.gov.pt
    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;
    }