private static byte[] CreateLicenseBytes(string name, string email, string productattr, string productval, string licid, LicenseData licdata) { var doc = CreateNotSignedLicenseDoc(name, email, productattr, productval, licid); var ms = new MemoryStream(); using (var xw = XmlWriter.Create(ms)) { doc.Save(xw); } if (licdata != null) { var sw = new StringWriter(); doc.Save(sw); licdata.LicenseXml = sw.ToString(); } byte[] data = ms.ToArray(); // sign binary representation of license var key = new EZRSA(1024); key.FromXmlString(Resources.privatekey); byte[] signature = key.SignData(data, new SHA1CryptoServiceProvider()); var mscmp = new MemoryStream(); using (var bw = new BinaryWriter(mscmp)) { bw.Write((int)signature.Length); bw.Write(signature); bw.Write((int)data.Length); bw.Write(data); } byte[] ar = mscmp.ToArray(); unchecked { for (int i = 0; i < ar.Length; i++) { ar[i] = (byte)(ar[i] ^ XOR_VALS[i % XOR_VALS.Length]); } } return(ar); }
public static string CreateLicense(string name, string email, string productattr, string productval, string licid, LicenseData licdata) { return(Convert.ToBase64String(CreateLicenseBytes(name, email, productattr, productval, licid, licdata))); }