コード例 #1
0
        public static LSLocalKey ReadLocalKey()
        {
            LSLocalKey lSLocalKey = null;
            string     keyPath    = Path.Combine(Application.persistentDataPath, "api.bin");

            var content = File.ReadAllText(keyPath);

            content = SecureStorage.Decrypt(content);

            lSLocalKey = LSLocalKey.FromString(content);
            return(lSLocalKey);
        }
コード例 #2
0
        void Awake()
        {
            _licensePath = Path.Combine(Application.persistentDataPath, Application.productName, "lock.lic");
            _apiPath     = Path.Combine(Application.persistentDataPath, Application.productName, "app.lic");

            _enumActiveStatus = ActivationStatus.Unknown;

            if (!File.Exists(_apiPath))
            {
                _enumActiveStatus = ActivationStatus.Unknown;
                throw new LicenseConfigurationException("Configuration invalid");
            }
            else
            {
                try
                {
                    //extended configuration options.
                    _lseo = new LicenseSpringExtendedOptions
                    {
                        HardwareID                = this.HardwareId,
                        LicenseFilePath           = _licensePath,
                        CollectHostNameAndLocalIP = true
                    };

                    //local config decryptor
                    _localKey = KeyStorage.ReadLocalKey();

                    //main configurations
                    LicenseSpringConfiguration lsConfig = new LicenseSpringConfiguration(_localKey.ApiKey,
                                                                                         _localKey.SharedKey,
                                                                                         _localKey.ProductCode,
                                                                                         _localKey.ApplicationName,
                                                                                         _localKey.ApplicationVersion,
                                                                                         _lseo);

                    _internalLicenseManager = (LicenseManager)LicenseManager.GetInstance();
                    _internalLicenseManager.Initialize(_lsConfig);

                    _installedLicense = (License)_internalLicenseManager.CurrentLicense();
                    SetLicenseStatus();
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex.Message);
                }
            }

            DontDestroyOnLoad(this);
        }
コード例 #3
0
        public static void SaveLocalKey(LSLocalKey localKey, string password)
        {
            try
            {
                var savePath      = Path.Combine(Application.persistentDataPath, "api.bin");
                var encryptResult = SecureStorage.Encrypt(localKey.ToString(), password);

                using (StreamWriter writer = new StreamWriter(savePath))
                {
                    writer.Write(encryptResult.Item1);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }