Exemple #1
0
        public string CreatMrz(MRZResult MRZResult, bool isMakeFullName)
        {
            if (string.IsNullOrEmpty(MRZResult.IssuingCountryIso) || string.IsNullOrEmpty(MRZResult.LastName) || string.IsNullOrEmpty(MRZResult.FirstName) || string.IsNullOrEmpty(MRZResult.DocumentNumber) ||
                string.IsNullOrEmpty(MRZResult.NationalityIso) || MRZResult.DateOfBirth.Value.Year < 1901 || string.IsNullOrEmpty(MRZResult.Gender) || MRZResult.ExpireDate.Value.Year < 1901)
            {
                return(string.Empty);
            }
            var line1 = "P<" + MRZResult.IssuingCountryIso + (MRZResult.LastName + "<<" + MRZResult.FirstName).Replace(" ", "<");

            if (isMakeFullName)
            {
                line1 = "P<" + MRZResult.IssuingCountryIso + (MRZResult.FirstName + "<" + MRZResult.LastName).Replace(" ", "<");
            }
            line1 = line1.PadRight(44, '<').Replace("-", "<");
            if (line1.Length > 44)
            {
                line1 = line1.Substring(0, 44);
            }
            var line2 = MRZResult.DocumentNumber.PadRight(9, '<') + CheckDigit(MRZResult.DocumentNumber.PadRight(9, '<')) + MRZResult.NationalityIso +
                        MRZResult.DateOfBirth.Value.ToString("yyMMdd") +
                        CheckDigit(MRZResult.DateOfBirth.Value.ToString("yyMMdd")) + MRZResult.Gender.Substring(0, 1) +
                        MRZResult.ExpireDate.Value.ToString("yyMMdd") +
                        CheckDigit(MRZResult.ExpireDate.Value.ToString("yyMMdd"));

            line2 = line2.PadRight(42, '<') + "0";
            var compositeCheckDigit =
                CheckDigit(line2.Substring(0, 10) + line2.Substring(13, 7) +
                           line2.Substring(21, 22));

            line2 = line2 + compositeCheckDigit.Replace("-", "<");
            return(line1 + line2);
        }
Exemple #2
0
        //Parsing is based on https://en.wikipedia.org/wiki/Machine-readable_passport
        //Useful information https://www.icao.int/publications/Documents/9303_p3_cons_en.pdf

        public string Parse(string newmrz)
        {
            //It should be done before calling this function
            //var newmrz = mrz.TrimEnd().Replace("«", "<<").Replace("&", "<").Replace("\n", "").Replace(" ", "");
            //newmrz = System.Text.RegularExpressions.Regex.Replace(newmrz, "[']+", "");
            var validationMessage = MRZValidationMessage(newmrz);

            if (!string.IsNullOrEmpty(validationMessage))
            {
                var errorObj = new MRZResult {
                    IsValid = false, ValidationMessage = validationMessage
                };
                return(JsonConvert.SerializeObject(errorObj));
            }

            var output = new MRZResult
            {
                DocumentType      = DocumentType(newmrz),
                Gender            = Gender(newmrz),
                ExpireDate        = ExpireDate(newmrz),
                IssuingCountryIso = IssuingCountryIso(newmrz),
                FirstName         = FirstName(newmrz),
                LastName          = LastName(newmrz),
                DocumentNumber    = DocumentNumber(newmrz),
                NationalityIso    = NationalityIso(newmrz),
                DateOfBirth       = DateOfBirth(newmrz),
                IsValid           = true
            };

            output.DocumentTypeDescription = DocumentTypeDescription(output.DocumentType);

            output.IssuingCountryName = IssuingCountryName(output.IssuingCountryIso);

            output.FullName = (output.FirstName + " " + output.LastName).Replace("  ", " ").Trim();

            output.NationalityName = NationalityName(output.NationalityIso);

            output.Age = output.DateOfBirth == null? null : (int?)(DateTime.Now.Subtract(output.DateOfBirth.Value).TotalDays / 365);

            output.IssueDate        = IssueDate(output.ExpireDate, output.NationalityIso);
            output.IssuingAuthority = IssuingAuthority(output.IssuingCountryIso);
            output.PlaceOfBirth     = PlaceOfBirth(output.NationalityIso);

            return(Newtonsoft.Json.JsonConvert.SerializeObject(output));
        }
Exemple #3
0
        public string Parse(string mrz)
        {
            var validationMessage = MRZValidationMessage(mrz);

            if (!string.IsNullOrEmpty(validationMessage))
            {
                var errorObj = new MRZResult {
                    IsValid = false, ValidationMessage = validationMessage
                };
                return(JsonConvert.SerializeObject(errorObj));
            }

            var output = new MRZResult
            {
                DocumentType      = DocumentType(mrz),
                Gender            = Gender(mrz),
                ExpireDate        = ExpireDate(mrz),
                IssuingCountryIso = IssuingCountryIso(mrz),
                FirstName         = FirstName(mrz),
                LastName          = LastName(mrz),
                DocumentNumber    = DocumentNumber(mrz),
                NationalityIso    = NationalityIso(mrz),
                DateOfBirth       = DateOfBirth(mrz)
            };

            output.DocumentTypeDescription = DocumentTypeDescription(output.DocumentType);

            output.IssuingCountryName = IssuingCountryName(output.IssuingCountryIso);

            output.FullName = (output.FirstName + " " + output.LastName).Replace("  ", " ").Trim();

            output.NationalityName = NationalityName(output.NationalityIso);

            //output.Age = (int)(DateTime.Now.Subtract(output.DateOfBirth).TotalDays / 365);

            return(JsonConvert.SerializeObject(output));
        }