/// <summary> /// Saves the license to disk. /// </summary> protected void PersistLicenseToDisk() { MemoryStream ms = null; try { //create the license XML ms = new MemoryStream(); XmlTextWriter tw = new XmlTextWriter(ms, System.Text.Encoding.UTF8); tw.WriteStartElement(_XML_LICENSE_NODE); tw.WriteAttributeString(_XML_REGISTRATION_ATTRIBUTE, RegistrationEmail); tw.WriteAttributeString(_XML_ACTIVATIONKEY_ATTRIBUTE, ActivationKey); tw.WriteEndElement(); tw.Flush(); //encrypt the XML ms.Position = 0; StreamReader sr = new StreamReader(ms); Cryptographer crypto = new Cryptographer(); string license = crypto.Encrypt(sr.ReadToEnd(), SystemInformation.ComputerName); //write the license to disk StreamWriter sw = new StreamWriter(LicensePath, false, System.Text.Encoding.UTF8); sw.Write(license); sw.Flush(); } catch (Exception exc) { throw new LicenseSaveException(exc); } finally { if (ms != null) ms.Close(); } }
/// <summary> /// Generates the activation key for a given email address. /// </summary> /// <param name="registrationName"></param> /// <returns></returns> protected string GenerateActivationKey(string registrationName) { Cryptographer crypto = new Cryptographer(); string keyHash = crypto.Hash(registrationName + _APPLICATION_KEY); System.Text.StringBuilder sb = new System.Text.StringBuilder(_ACTIVATION_KEY_LENGTH); foreach (char c in keyHash) sb.Append(_READABLE_HASH_CHARS[Convert.ToInt32((int)c / ((float)127 / (float)32))]); return sb.ToString(); }
/// <summary> /// Gets the MD5 checksum for the passed WSDL, in hexadecimal format. /// </summary> /// <param name="wsdl">WSDL to generate checksum.</param> /// <returns>Checksum in hexadecimal format.</returns> public string GetWsdlChecksum(string wsdl) { Cryptographer crypto = new Cryptographer(); return IOUtilities.ConvertToHex(crypto.Hash(wsdl)); }