示例#1
0
        /// <inheritdoc />
        protected override byte[] GetDataToSign(int privateKeyLength)
        {
            var iccPublicKeyModulus  = IccPublicKey.Modulus.FromHexa();
            var iccPublicKeyExponent = IccPublicKey.Exponent.FromHexa();

            DataFormat = 0x04;

            PublicKeyLength         = (byte)iccPublicKeyModulus.Length;
            PublicKeyExponentLength = (byte)iccPublicKeyExponent.Length;

            PublicKeyorLeftmostDigitsofthePublicKey = new byte[privateKeyLength - 42];

            // ICC Public Key Remainder (0 or NI – NCA + 42) - Present only if NI > NCA – 42 and consists of the NI – NCA + 42 least significant bytes of the ICC Public Key
            byte[] iccPublicKeyRemainder;

            if (IccPublicKey.Modulus.Length <= privateKeyLength - 42)
            {
                Array.Copy(iccPublicKeyModulus, PublicKeyorLeftmostDigitsofthePublicKey, iccPublicKeyModulus.Length);
                // pad with 'BB'
                for (var i = iccPublicKeyModulus.Length; i < privateKeyLength - 42; i++)
                {
                    PublicKeyorLeftmostDigitsofthePublicKey[i] = 0xBB;
                }
                iccPublicKeyRemainder = new byte[0];
            }
            else
            {
                PublicKeyorLeftmostDigitsofthePublicKey = iccPublicKeyModulus.Take(privateKeyLength - 42).ToArray();
                iccPublicKeyRemainder = new byte[iccPublicKeyModulus.Length - privateKeyLength + 42];
                // TODO Set a correct value !!
            }

            var applicationPan = ApplicationPan
                                 .ToHexa('\0')
                                 .PadRight(20, 'F')
                                 .FromHexa();

            return(DataFormat.ToByteArray()
                   .Concat(applicationPan)
                   .Concat(CertificateExpirationDate)
                   .Concat(CertificateSerialNumber)
                   .Concat(HashAlgorithmIndicator.ToByteArray())
                   .Concat(PublicKeyAlgorithmIndicator.ToByteArray())
                   .Concat(PublicKeyLength.ToByteArray())
                   .Concat(PublicKeyExponentLength.ToByteArray())
                   .Concat(PublicKeyorLeftmostDigitsofthePublicKey)
                   .Concat(iccPublicKeyRemainder)
                   .Concat(iccPublicKeyExponent)
                   // TODO Add Static Data to be authenticated
                   .ToArray());
        }
        /// <inheritdoc />
        protected override byte[] GetDataToSign(int privateKeyLength)
        {
            DataFormat = 0x03;

            PadPattern = new byte[privateKeyLength - 26];
            for (var i = 0; i < privateKeyLength - 26; i++)
            {
                PadPattern[i] = 0xBB;
            }

            return(DataFormat.ToByteArray()
                   .Concat(HashAlgorithmIndicator.ToByteArray())
                   .Concat(DataAuthenticationCode)
                   .Concat(PadPattern)
                   .Concat(StaticDataToBeAuthenticated)
                   .ToArray());
        }
示例#3
0
        /// <inheritdoc />
        protected override byte[] GetDataToSign(int privateKeyLength)
        {
            var issuerPublicKeyModulus  = IssuerPublicKey.Modulus.FromHexa();
            var issuerPublicKeyExponent = IssuerPublicKey.Exponent.FromHexa();

            DataFormat = 0x02;

            PublicKeyLength         = (byte)issuerPublicKeyModulus.Length;
            PublicKeyExponentLength = (byte)issuerPublicKeyExponent.Length;

            PublicKeyorLeftmostDigitsofthePublicKey = new byte[privateKeyLength - 36];

            // Issuer Public Key Remainder (0 or NI – NCA + 36) - Present only if NI > NCA – 36 and consists of the NI – NCA + 36 least significant bytes of the Issuer Public Key
            byte[] issuerPublicKeyRemainder;

            if (IssuerPublicKey.Modulus.Length <= privateKeyLength - 36)
            {
                Array.Copy(issuerPublicKeyModulus, PublicKeyorLeftmostDigitsofthePublicKey, issuerPublicKeyModulus.Length);
                // pad with 'BB'
                for (var i = issuerPublicKeyModulus.Length; i < privateKeyLength - 36; i++)
                {
                    PublicKeyorLeftmostDigitsofthePublicKey[i] = 0xBB;
                }
                issuerPublicKeyRemainder = new byte[0];
            }
            else
            {
                PublicKeyorLeftmostDigitsofthePublicKey = issuerPublicKeyModulus.Take(privateKeyLength - 36).ToArray();
                issuerPublicKeyRemainder = new byte[issuerPublicKeyModulus.Length - privateKeyLength + 36];
            }

            return(DataFormat.ToByteArray()
                   .Concat(IssuerIdentifier)
                   .Concat(CertificateExpirationDate)
                   .Concat(CertificateSerialNumber)
                   .Concat(HashAlgorithmIndicator.ToByteArray())
                   .Concat(PublicKeyAlgorithmIndicator.ToByteArray())
                   .Concat(PublicKeyLength.ToByteArray())
                   .Concat(PublicKeyExponentLength.ToByteArray())
                   .Concat(PublicKeyorLeftmostDigitsofthePublicKey)
                   .Concat(issuerPublicKeyRemainder)
                   .Concat(issuerPublicKeyExponent)
                   .ToArray());
        }