private void GenerateKeyAndSend(String Name, String Organisation, String EmailAddress, bool SendMail) { //Opbouwen compleet bericht String MessageToEncrypt = "<xml><applicatie name=\"Copying Machine\" version=\"2.00\"/>"; MessageToEncrypt += "<user name=\""; MessageToEncrypt += Name; MessageToEncrypt += "\" organisation=\""; MessageToEncrypt += Organisation; MessageToEncrypt += "\" id=\""; MessageToEncrypt += System.DateTime.Now.ToShortDateString() + System.DateTime.Now.ToShortTimeString(); MessageToEncrypt += "\" emailaddress=\""; MessageToEncrypt += EmailAddress; MessageToEncrypt += "\"/></xml>"; System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); Byte[] bytes = encoding.GetBytes(MessageToEncrypt); byte[] dataToEncrypt = new byte[1 + bytes.Length]; //Add the checksum to the xml int iChecksum = 0; for (int i = 0; i < MessageToEncrypt.Length; i++) { iChecksum = iChecksum + bytes[i]; dataToEncrypt[i + 1] = bytes[i]; } iChecksum = (iChecksum & 0x07); iChecksum = (iChecksum << 5) & 0xFF; iChecksum = iChecksum | 0x20; dataToEncrypt[0] = Convert.ToByte(iChecksum); //Construct the name of the keyfile to be generated String KeyFile; KeyFile = "Keys\\copymach_"; KeyFile += Name.ToLower(); KeyFile += ".cmk"; KeyFile = KeyFile.Replace(" ", ""); if (!Directory.Exists("Keys")) { Directory.CreateDirectory("Keys"); } //Create the key Key(KeyFile, dataToEncrypt, dataToEncrypt.Length); //Send e-mail if (SendMail) { MailKey(KeyFile, EmailAddress); } }