예제 #1
0
        /// <summary>
        /// Constructs a new EF_DG15 file.
        /// </summary>
        /// <param name="data">bytes of the EF_DG15 file</param>
        public DG15File(byte[] data)
        {
            dgNumber = 15;
            raw      = new byte[data.Length];
            Array.Copy(data, RawBytes, data.Length);
            MemoryStream      dg15MemStream = new MemoryStream(data);
            BERTLVInputStream dg15Stream    = new BERTLVInputStream(dg15MemStream);
            int tag = dg15Stream.readTag();

            if (tag != IDGFile.EF_DG15_TAG)
            {
                throw new ArgumentException("Expected EF_DG15_TAG");
            }
            int dg15Length = dg15Stream.readLength();

            byte[] value = dg15Stream.readValue();


            Asn1InputStream aIn = new Asn1InputStream(value);

            /*Asn1Sequence seq = (Asn1Sequence) aIn.ReadObject();
             * string alg =  ((DerSequence) seq[0])[0].ToString();
             * byte[] publicKey = ((DerBitString)seq[1]).GetBytes();*/

            SubjectPublicKeyInfo info = SubjectPublicKeyInfo.GetInstance(aIn.ReadObject());

            PublicKey = RsaPublicKeyStructure.GetInstance(info.GetPublicKey());
        }
예제 #2
0
        /// <summary>
        /// Constructs a new EF_SOD file.
        /// </summary>
        /// <param name="data">bytes of the EF_DG1 file</param>
        public SODFile(byte[] data)
        {
            MemoryStream dataStream = new MemoryStream(data);
            BERTLVInputStream tlvStream = new BERTLVInputStream(dataStream);
            int tag = tlvStream.readTag();
            if (tag != IDGFile.EF_SOD_TAG) throw new ArgumentException("Expected EF_SOD_TAG");
            int length = tlvStream.readLength();

            Asn1InputStream sodAsn1 = new Asn1InputStream(dataStream);
            DerSequence seq = (DerSequence)sodAsn1.ReadObject();
            DerObjectIdentifier objectIdentifier = (DerObjectIdentifier)seq[0];

            //DerTaggedObject o = (DerTaggedObject)seq[1];
            DerSequence s2 = (DerSequence)((DerTaggedObject)seq[1]).GetObject();
            IEnumerator e = s2.GetEnumerator();
            e.MoveNext();
            DerInteger version = (DerInteger)e.Current;
            e.MoveNext();
            Asn1Set digestAlgorithms = (Asn1Set)e.Current;
            e.MoveNext();
            ContentInfo contentInfo = ContentInfo.GetInstance(e.Current);

            Asn1Set signerInfos = null;
            bool certsBer = false;
            bool crlsBer = false;
            Asn1Set certificates = null;
            Asn1Set crls = null;

            while (e.MoveNext())
            {
                Object o = e.Current;
                if (o is Asn1TaggedObject)
                {
                    Asn1TaggedObject tagged = (Asn1TaggedObject)o;
                    switch (tagged.TagNo)
                    {
                        case 0:
                            certsBer = tagged is BerTaggedObject;
                            certificates = Asn1Set.GetInstance(tagged, false);
                            break;
                        case 1:
                            crlsBer = tagged is BerTaggedObject;
                            crls = Asn1Set.GetInstance(tagged, false);
                            break;
                        default:
                            throw new ArgumentException("unknown tag value " + tagged.TagNo);
                    }
                }
                else
                {
                    signerInfos = (Asn1Set)o;
                }
            }
            _signedData = new SignedData(digestAlgorithms, contentInfo, certificates, crls, signerInfos);
            byte[] content = ((DerOctetString)contentInfo.Content).GetOctets();
            Asn1InputStream inStream = new Asn1InputStream(content);
            _lds = new LdsSecurityObject((Asn1Sequence)inStream.ReadObject());
        }
예제 #3
0
 /// <summary>
 /// Constructs a new EF_DG1 file.
 /// </summary>
 /// <param name="data">bytes of the EF_DG1 file</param>
 public DG1File(byte[] data)
 {
     dgNumber = 1;
     raw = new byte[data.Length];
     Array.Copy(data,RawBytes,data.Length);
     MemoryStream dg1MemStream = new MemoryStream(data);
     BERTLVInputStream dg1Stream = new BERTLVInputStream(dg1MemStream);
     int tag = dg1Stream.readTag();
     if (tag != IDGFile.EF_DG1_TAG) throw new ArgumentException("Expected EF_DG1_TAG");
     int dg1Length = dg1Stream.readLength();
     dg1Stream.skipToTag(MRZ_INFO_TAG);
     dg1Stream.readLength();
     _mrz = new MRZInfo(dg1MemStream);
 }
예제 #4
0
        /// <summary>
        /// Constructs a new EF_DG1 file.
        /// </summary>
        /// <param name="data">bytes of the EF_DG1 file</param>
        public DG1File(byte[] data)
        {
            dgNumber = 1;
            raw      = new byte[data.Length];
            Array.Copy(data, RawBytes, data.Length);
            MemoryStream      dg1MemStream = new MemoryStream(data);
            BERTLVInputStream dg1Stream    = new BERTLVInputStream(dg1MemStream);
            int tag = dg1Stream.readTag();

            if (tag != IDGFile.EF_DG1_TAG)
            {
                throw new ArgumentException("Expected EF_DG1_TAG");
            }
            int dg1Length = dg1Stream.readLength();

            dg1Stream.skipToTag(MRZ_INFO_TAG);
            dg1Stream.readLength();
            _mrz = new MRZInfo(dg1MemStream);
        }
예제 #5
0
        /// <summary>
        /// Constructs a new EF_DG15 file.
        /// </summary>
        /// <param name="data">bytes of the EF_DG15 file</param>
        public DG15File(byte[] data)
        {
            dgNumber = 15;
            raw = new byte[data.Length];
            Array.Copy(data, RawBytes, data.Length);
            MemoryStream dg15MemStream = new MemoryStream(data);
            BERTLVInputStream dg15Stream = new BERTLVInputStream(dg15MemStream);
            int tag = dg15Stream.readTag();
            if (tag != IDGFile.EF_DG15_TAG) throw new ArgumentException("Expected EF_DG15_TAG");
            int dg15Length = dg15Stream.readLength();
            byte[] value = dg15Stream.readValue();

            Asn1InputStream aIn = new Asn1InputStream(value);
            /*Asn1Sequence seq = (Asn1Sequence) aIn.ReadObject();
            string alg =  ((DerSequence) seq[0])[0].ToString();
            byte[] publicKey = ((DerBitString)seq[1]).GetBytes();*/

            SubjectPublicKeyInfo info = SubjectPublicKeyInfo.GetInstance(aIn.ReadObject());
            PublicKey = RsaPublicKeyStructure.GetInstance(info.GetPublicKey());
        }
예제 #6
0
        /// <summary>
        /// Constructs a new EF_SOD file.
        /// </summary>
        /// <param name="data">bytes of the EF_DG1 file</param>
        public SODFile(byte[] data)
        {
            MemoryStream      dataStream = new MemoryStream(data);
            BERTLVInputStream tlvStream  = new BERTLVInputStream(dataStream);
            int tag = tlvStream.readTag();

            if (tag != IDGFile.EF_SOD_TAG)
            {
                throw new ArgumentException("Expected EF_SOD_TAG");
            }
            int length = tlvStream.readLength();

            Asn1InputStream     sodAsn1          = new Asn1InputStream(dataStream);
            DerSequence         seq              = (DerSequence)sodAsn1.ReadObject();
            DerObjectIdentifier objectIdentifier = (DerObjectIdentifier)seq[0];

            //DerTaggedObject o = (DerTaggedObject)seq[1];
            DerSequence s2 = (DerSequence)((DerTaggedObject)seq[1]).GetObject();
            IEnumerator e  = s2.GetEnumerator();

            e.MoveNext();
            DerInteger version = (DerInteger)e.Current;

            e.MoveNext();
            Asn1Set digestAlgorithms = (Asn1Set)e.Current;

            e.MoveNext();
            ContentInfo contentInfo = ContentInfo.GetInstance(e.Current);

            Asn1Set signerInfos  = null;
            bool    certsBer     = false;
            bool    crlsBer      = false;
            Asn1Set certificates = null;
            Asn1Set crls         = null;

            while (e.MoveNext())
            {
                Object o = e.Current;
                if (o is Asn1TaggedObject)
                {
                    Asn1TaggedObject tagged = (Asn1TaggedObject)o;
                    switch (tagged.TagNo)
                    {
                    case 0:
                        certsBer     = tagged is BerTaggedObject;
                        certificates = Asn1Set.GetInstance(tagged, false);
                        break;

                    case 1:
                        crlsBer = tagged is BerTaggedObject;
                        crls    = Asn1Set.GetInstance(tagged, false);
                        break;

                    default:
                        throw new ArgumentException("unknown tag value " + tagged.TagNo);
                    }
                }
                else
                {
                    signerInfos = (Asn1Set)o;
                }
            }
            _signedData = new SignedData(digestAlgorithms, contentInfo, certificates, crls, signerInfos);
            byte[]          content  = ((DerOctetString)contentInfo.Content).GetOctets();
            Asn1InputStream inStream = new Asn1InputStream(content);

            _lds = new LdsSecurityObject((Asn1Sequence)inStream.ReadObject());
        }