コード例 #1
0
        public bool Decrypt(byte[] encLic)
        {
            byte[] array = default(byte[]);
            try
            {
                using (Aes aes = Aes.Create())
                {
                    aes.Key = Encoding.ASCII.GetBytes("I'd tell you a joke about UDP, but I'm not sure you'd get it".Substring(0, 32));
                    aes.IV  = this._aesIV;
                    ICryptoTransform transform = aes.CreateDecryptor(aes.Key, aes.IV);
                    using (MemoryStream stream = new MemoryStream(encLic))
                    {
                        using (CryptoStream cryptoStream = new CryptoStream(stream, transform, CryptoStreamMode.Read))
                        {
                            array = new byte[encLic.Length];
                            cryptoStream.Read(array, 0, array.Length);
                        }
                    }
                }
            }
            catch (Exception)
            {
                array = new byte[0];
                return(false);
            }
            DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(LicenceRegistryValue));
            int num = Array.IndexOf(array, (byte)0);

            if (num == -1)
            {
                num = array.Length;
            }
            MemoryStream stream2 = new MemoryStream(array, 0, num);

            try
            {
                LicenceRegistryValue licenceRegistryValue = (LicenceRegistryValue)dataContractJsonSerializer.ReadObject(stream2);
                this.ProductKey         = licenceRegistryValue.Key;
                this.LicencedCompany    = licenceRegistryValue.Company;
                this.LicencedIndividual = licenceRegistryValue.User;
                this.EMail           = licenceRegistryValue.Email;
                this.UniqueMachineID = licenceRegistryValue.UniqueMachineID;
                this.Expiry          = DateTime.Parse(licenceRegistryValue.Expiry);
                this.Type            = (UltamationLicenceType)Enum.Parse(typeof(UltamationLicenceType), licenceRegistryValue.Type);
            }
            catch (Exception)
            {
                this.SetToUnlicenced();
                return(false);
            }
            return(true);
        }
コード例 #2
0
        public byte[] Encrypt()
        {
            DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(LicenceRegistryValue));
            MemoryStream         memoryStream         = new MemoryStream();
            LicenceRegistryValue licenceRegistryValue = new LicenceRegistryValue();

            licenceRegistryValue.Key             = this.ProductKey;
            licenceRegistryValue.Company         = this.LicencedCompany;
            licenceRegistryValue.User            = this.LicencedIndividual;
            licenceRegistryValue.Email           = this.EMail;
            licenceRegistryValue.UniqueMachineID = this.UniqueMachineID;
            licenceRegistryValue.Expiry          = this.Expiry.ToLongDateString();
            licenceRegistryValue.Type            = Enum.GetName(typeof(UltamationLicenceType), this.Type);
            try
            {
                dataContractJsonSerializer.WriteObject(memoryStream, licenceRegistryValue);
                byte[] buffer = memoryStream.GetBuffer();
                using (Aes aes = Aes.Create())
                {
                    aes.Key = Encoding.ASCII.GetBytes("I'd tell you a joke about UDP, but I'm not sure you'd get it".Substring(0, 32));
                    aes.IV  = this._aesIV;
                    ICryptoTransform transform = aes.CreateEncryptor(aes.Key, aes.IV);
                    using (MemoryStream memoryStream2 = new MemoryStream())
                    {
                        using (CryptoStream cryptoStream = new CryptoStream(memoryStream2, transform, CryptoStreamMode.Write))
                        {
                            cryptoStream.Write(buffer, 0, buffer.Length);
                            cryptoStream.FlushFinalBlock();
                            return(memoryStream2.ToArray());
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }