public string Serialize(License license, IEncoder encoder)
 {
     byte[] data;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         OldLicenseSerializer.WriteLicenseToStream(license, memoryStream);
         data = memoryStream.ToArray();
     }
     byte[] data2 = encoder.Encode(data);
     return(Base32Encoder.Encode(data2));
 }
        private static License ReadLicenseFromStream(Stream stream)
        {
            License result;

            try
            {
                License      license      = new License();
                BinaryReader binaryReader = new BinaryReader(stream, Encoding.Unicode);
                OldLicenseSerializer.OldLicenseType oldLicenseType = (OldLicenseSerializer.OldLicenseType)binaryReader.ReadByte();
                license.PurchaseId = "shareit:" + binaryReader.ReadInt64().ToString();
                license.Version    = binaryReader.ReadByte();
                DateTime dateTime = OldLicenseSerializer.ReadDateTime(binaryReader);
                string   text     = OldLicenseSerializer.ReadBytePrefixedString(binaryReader);
                string   text2    = OldLicenseSerializer.ReadBytePrefixedString(binaryReader);
                license.LicensedTo = text;
                if (text2.Length > 0 && text2 != text)
                {
                    License expr_79 = license;
                    expr_79.LicensedTo = expr_79.LicensedTo + ", " + text2;
                }
                license.Capacity = 1;
                license.Binding  = LicenseBinding.User;
                if (oldLicenseType == OldLicenseSerializer.OldLicenseType.Real)
                {
                    if (text2.Length > 0)
                    {
                        license.Type    = LicenseType.Corporate;
                        license.Binding = LicenseBinding.Seat;
                    }
                    else
                    {
                        license.Type = LicenseType.Personal;
                    }
                    license.StartTime    = DateTime.MinValue;
                    license.EndTime      = DateTime.MaxValue;
                    license.PurchaseDate = dateTime;
                }
                else
                {
                    license.Type         = LicenseType.Evaluation;
                    license.StartTime    = dateTime;
                    license.EndTime      = dateTime.AddDays(30.0);
                    license.PurchaseDate = dateTime;
                }
                result = license;
            }
            catch (Exception inner)
            {
                throw new LicensingException("Can not parse license.", inner);
            }
            return(result);
        }
        public License Deserialize(string key, IDecoder decoder)
        {
            byte[] array = Base32Decoder.Decode(key);
            if (OldLicenseSerializer.IsEmpty(array))
            {
                return(null);
            }
            byte[] array2 = decoder.Decode(array);
            if (OldLicenseSerializer.IsEmpty(array2))
            {
                return(null);
            }
            License result;

            using (MemoryStream memoryStream = new MemoryStream(array2))
            {
                License license = OldLicenseSerializer.ReadLicenseFromStream(memoryStream);
                result = license;
            }
            return(result);
        }