Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="model">Card DGI model.</param>
 /// <param name="data">Card data.</param>
 /// <param name="issuerContext"></param>
 /// <param name="iccContext"></param>
 public DgiBuilder(EmvPersonalizationModel model, EmvPersonalizationData data, EmvIssuerContext issuerContext, EmvIccContext iccContext)
 {
     this.data          = data;
     this.model         = model;
     this.issuerContext = issuerContext;
     this.iccContext    = iccContext;
 }
Esempio n. 2
0
        void ComputeIssuerContext()
        {
            var caModulusLength     = new BigInteger(caPrivateKey.Modulus, 16).BitLength / 8;
            var issuerPublicKey     = certificateData.IssuerPrivateKey.GetPublicKey();
            var issuerModulusLength = new BigInteger(issuerPublicKey.Modulus, 16).BitLength / 8;

            var issuerPublicKeyCertificate = new IssuerPublicKeyCertificate
            {
                HashAlgorithmIndicator      = certificateData.HashAlgorithmIndicator.FromHexa().First(),
                IssuerIdentifier            = certificateData.IssuerIdentifier.FromHexa(),
                CertificateExpirationDate   = certificateData.ExpirationDate.FromHexa(),
                CertificateSerialNumber     = certificateData.SerialNumber.FromHexa(),
                PublicKeyAlgorithmIndicator = certificateData.PublicKeyAlgorithmIndicator.FromHexa().First(),
                IssuerPublicKey             = issuerPublicKey
            };

            IssuerContext = new EmvIssuerContext()
            {
                CaPublicKeyIndex = certificateData.CaPublicKeyIndex,
                IssuerPrivateKey = certificateData.IssuerPrivateKey
            };

            // 90   Issuer Public Key Certificate (Nca)
            IssuerContext.IssuerPublicKeyCertificate = issuerPublicKeyCertificate.GenerateCertificate(caPrivateKey.GetPrivateKey()).ToHexa();

            // 92   Issuer Public Key Remainder (Ni-Nca+36)
            if (issuerModulusLength > caModulusLength - 36)
            {
                IssuerContext.IssuerPublicKeyRemainder = issuerPublicKey.Modulus.FromHexa().Skip(caModulusLength - 36).ToArray().ToHexa();
            }

            // 9F32 Issuer Public Key Exponent (1 or 3)
            IssuerContext.IssuerPrivateKey.PublicExponent = issuerPublicKey.Exponent.FromHexa().ToHexa();
        }
Esempio n. 3
0
        public void BuildTlvData_Partial()
        {
            var emvIssuerContext = new EmvIssuerContext();

            emvIssuerContext.CaPublicKeyIndex = "01";
            var tlv = emvIssuerContext.BuildTlvData();

            Assert.AreEqual(1, tlv.Count);
            Assert.AreEqual("8F 01 01", tlv[0].ToByteArray().ToHexa());
        }
Esempio n. 4
0
        public void BuildTlvData_All()
        {
            var emvIssuerContext = new EmvIssuerContext();

            emvIssuerContext.CaPublicKeyIndex           = "01";
            emvIssuerContext.IssuerPublicKeyCertificate = "0203";
            emvIssuerContext.IssuerPublicKeyRemainder   = "040506";
            emvIssuerContext.IssuerPrivateKey           = new PrivateKey {
                PublicExponent = "07080900"
            };
            var tlv = emvIssuerContext.BuildTlvData();

            Assert.AreEqual(4, tlv.Count);
            Assert.AreEqual("8F 01 01", tlv.First(t => t.Tag == 0x8F).ToByteArray().ToHexa());
            Assert.AreEqual("90 02 02 03", tlv.First(t => t.Tag == 0x90).ToByteArray().ToHexa());
            Assert.AreEqual("92 03 04 05 06", tlv.First(t => t.Tag == 0x92).ToByteArray().ToHexa());
            Assert.AreEqual("9F 32 04 07 08 09 00", tlv.First(t => t.Tag == 0x9F32).ToByteArray().ToHexa());
        }