Esempio n. 1
0
 public BoundMessage(string PayloadIn, Cryptographic Cryptographic)
 {
     if (Cryptographic == null) {
         Payload = PayloadIn;
         }
     else {
         Cryptography.Authentication Authentication =
             Cryptography.AuthenticationCode(Cryptographic.Authentication);
         Cryptography.Key Key = new Cryptography.Key(Cryptographic.Secret, Authentication,
                    Cryptography.Encryption.Unknown);
         BindMessage(PayloadIn, Cryptographic.Ticket, Authentication, Key);
         }
 }
Esempio n. 2
0
        private void Register(String Name, String Surname, String BirthDate, String IdNumber)
        {
            /* Local variables */
            List <String> responsesDD01 = new List <String>(), responsesDD02 = new List <String>();

            Char[] decipherKeyArray = new Char[256], signingKeyArray = new Char[256];
            String decipherKeyString, signingKeyString;

            /*  DF 0010 - file to decipher */
            responsesDD01.Add(HexToBytenByteToHex.ToString(SendMessage("00 A4 01 0C 02 00 10")));                   //Select DF
            responsesDD01.Add(HexToBytenByteToHex.ToString(SendMessage("00 A4 02 0C 02 0E 01")));                   //Select file with public key
            responsesDD01.Add(HexToBytenByteToHex.ToString(SendMessage("00 B0 00 00 F0")));                         //Read bytes (from public key transparent file)
            Array.Copy(responsesDD01[2].ToCharArray(), 8, decipherKeyArray, 0, 256);                                //Cut only these bytes, which belong to decpiher key
            decipherKeyString = new String(decipherKeyArray);
            responsesDD01.Add(HexToBytenByteToHex.ToString(SendMessage("00 A4 03 0C")));                            //Back to MF

            /*  DF 0020 - file to signing */
            responsesDD02.Add(HexToBytenByteToHex.ToString(SendMessage("00 A4 01 0C 02 00 20")));                   //Select DF
            responsesDD02.Add(HexToBytenByteToHex.ToString(SendMessage("00 20 00 81 08 31 32 33 34 35 36 37 38"))); //Verify
            responsesDD02.Add(HexToBytenByteToHex.ToString(SendMessage("00 A4 02 0C 02 0E 01")));                   //Select file with public key
            responsesDD02.Add(HexToBytenByteToHex.ToString(SendMessage("00 B0 00 00 F0")));                         //Read bytes (from public key transparent file)
            Array.Copy(responsesDD02[3].ToCharArray(), 8, signingKeyArray, 0, 256);                                 //Cut only these bytes, which belong to decpiher key
            signingKeyString = new String(signingKeyArray);
            responsesDD02.Add(HexToBytenByteToHex.ToString(SendMessage("00 A4 03 0C")));                            //Back to MF


            /* Creating certificate based on public key generated on SmartCard */
            Certificate clientDecipherCertificate = new Certificate(), clientSigningCertificate = new Certificate(), caCertificate = new Certificate();

            Cryptography.Key clientDecpiherKey = new Cryptography.Key(), clientSigningKey = new Cryptography.Key(), caKey = new Cryptography.Key();

            clientDecpiherKey.ReadPublicKeyFromCardResponse(decipherKeyString);
            clientSigningKey.ReadPublicKeyFromCardResponse(signingKeyString);

            caKey.ReadCaPrivateKeyFromFile();
            System.Security.Cryptography.X509Certificates.X509Certificate2 caCert = caCertificate.LoadPKCS12FromFile();
            clientDecipherCertificate.CreateSubjectX509Name(TextBox_Name.Text, TextBox_Surname.Text, TextBox_IdNumber.Text);
            clientSigningCertificate.CreateSubjectX509Name(TextBox_Name.Text, TextBox_Surname.Text, TextBox_IdNumber.Text);
            clientDecipherCertificate.CreateCertificate(clientDecpiherKey, caKey, caCert);
            clientSigningCertificate.CreateCertificate(clientSigningKey, caKey, caCert);

            /* Serialize data and save to file */
            xmlManager.SerializeAndSavePersonRecord(personList, Name, Surname, BirthDate, IdNumber, clientDecipherCertificate.GetCertificateAsString, clientSigningCertificate.GetCertificateAsString);
            /* Stop connection to card */
            //StopConnection();
        }
Esempio n. 3
0
 protected void InitServerContext(Cryptography.Authentication AuthenticationIn)
 {
     Authentication = AuthenticationIn;
     MasterSeed = new Cryptography.Key (Authentication);
 }
Esempio n. 4
0
 public Seed(int ExpiryHours)
     : base()
 {
     MasterSeed = new Cryptography.Key ();
     Expiry = "ExpiryTime" + ExpiryHours.ToString ();
 }
Esempio n. 5
0
        protected int Unpack()
        {
            int index = 0;
            byte x;

            x = Ticket [index++];
            if (x != 0) throw new Exception ("Bad ticket");
            x = Ticket [index++]; // ignore, checked already
            Authentication = (Cryptography.Authentication) Ticket [index++];
            Encryption = (Cryptography.Encryption) Ticket [index++];

            byte [] MasterKeyData = new byte [MasterKeyBytes];
            for (int i = 0; i < MasterKeyBytes; i++) {
                MasterKeyData [i] = Ticket [index++];
                }
            MasterKey = new Cryptography.Key (MasterKeyData, Authentication, Encryption);

            x = Ticket [index++];
            byte [] AccountIDData = new byte [x];
            int At = x; // No @ in string would mean it is all account, no domain
            for (int i = 0; i < x; i++) {
                if (Ticket[index] == '@') {
                    At = i;
                    }
                AccountIDData [i] = Ticket [index++];
                }
            Account = UTF8Encoding.GetString (AccountIDData, 0, At);
            Account = UTF8Encoding.GetString (AccountIDData, At-1, x-At-1);

            return index;
        }
Esempio n. 6
0
 public TicketData()
 {
     MasterKey = new Cryptography.Key (Authentication);
     // Derrive the Authentication and Encryption Keys
 }