コード例 #1
0
        public LicenseResult(byte[] licenseData, Client client)
        {
            try
            {
                var rsaSigner = new RSASigner();
                //We always should have the same format
                using (var sourceStream = new MemoryStream(licenseData))
                using (var reader = new BinaryReader(sourceStream))
                {
                    long dataLength = reader.ReadInt64();
                    byte[] data = reader.ReadBytes((int) dataLength);
                    byte[] sign = reader.ReadBytes((int) (licenseData.Length-8-dataLength));

                    var signBuffer = RSASigner.GetSignBuffer(data,new[]{BitConverter.GetBytes(DateTime.UtcNow.Year),client.GetSerialNumber()});
                    bool valid = rsaSigner.Validate(signBuffer, sign);
                    if (!valid)
                        throw new LicenseValidationException("License sign is invalid (maybe clock shifting)");
                    LicenseData = client.Decrypt(data);
                }
            }
            catch (Exception e)
            {
                throw new LicenseException("License corrupted", e);
            }
        }
コード例 #2
0
 public static LicenseResult FromOfflineString(string offlineString, Client client)
 {
     return new LicenseResult(DataEncoder.FromHexString(offlineString),client);
 }