浅谈flex的Licence技术

 

       有些朋友在开发flex经常遇到一些问题,就是有一个产品的swf无法做授权管理。给人家非法下载项目进行使用,导致一些不良影响。一直以来都有一些朋友问我怎么对flex的swf做一个最灵活的授权。那时我不便公开我的授权秘密,因为这个也是为了我的swf授权不给破解。现在我也采用新一代的授权加密框架,我现在也给大家介绍一下我之前的flex加密框架。

     首先我的flex授权采用的swf+swc的模式。项目的主力是swf文件的,授权文件在swc。每次在客户非法更换项目名称,项目路径时候,都必须要加载新的swc授权文件才可以正常运行。swc文件授权约束包括:项目名称、项目路径和项目有效期。

    我把整个授权源代码贴出来,和大家一起学习分享,详细的描述就不多说了。

package com.shine.framework.Licence
{
	import com.shine.framework.Browser.BrowserUtils;
	import com.shine.framework.Swc.SwcManager;
	import com.shine.framework.core.util.ReferenceUtil;
	
	import mx.controls.Alert;
	
	public class LicenceManager
	{
		private static var _instance:LicenceManager;
		//licence数据 
		public var licence:String="";
		//licence 模式
		public var licenceConfig:String="";
		//licence 状态
		public var licenceStatus:Boolean=false;
		//返回值方法
		public var returnMethod:Function;
		
		public function LicenceManager(enforcer:SingletonEnforcer)
		{
		}
		
		public static function getInstance():LicenceManager
		{
			if (LicenceManager._instance == null)
			{
				LicenceManager._instance=new LicenceManager(new SingletonEnforcer());
			}
			return LicenceManager._instance;
		}
		
		//加载swc
		public function loadLicence(swcUrl:String,returnMethod:Function=null):void{
			var swcManage:SwcManager =new SwcManager;
			swcManage.loadSwc(swcUrl,loadComplete);
			if(returnMethod!=null){
				this.returnMethod=returnMethod;
			}
		}
		
		//加载完成
		private function loadComplete():void{
			if(checkLicenceName()==true&&checkLicenceUrl()==true){
				licenceStatus=true;
			}else{
				licenceStatus=false;
			}
			
			if(returnMethod!=null){
				this.returnMethod.call(this);
			}
		}
		
		//检查licence name
		public function checkLicenceName():Boolean{
			var o:Object=ReferenceUtil.referenceClass("com.shine.framework.Licence.file::LicenceFile");
			if(licence.length!=0){
				if(o.licence!=null&&String(o.licence).length!=0){
					if(licence==String(o.licence))
						return true;
				}else{
					return false;
				}
			}
			return false;
		}
		
		//检查licence name
		public function checkLicenceUrl():Boolean{
			var o:Object=ReferenceUtil.referenceClass("com.shine.framework.Licence.file::LicenceFile");
			if(o.licenceUrl!=null&&String(o.licenceUrl).length!=0){
				if(BrowserUtils.getBrowserBaseUrl()==String(o.licenceUrl))
					return true;
			}else{
				return true;
			}
			return false;
		}
	}
}
class SingletonEnforcer
{
}

package com.shine.framework.Licence.file
{
	public class LicenceFile
	{
		public var licence:String="nms4";
		
		public var licenceUrl:String="http://127.0.0.1";
		
		public var licenceDate:String="2011-03-07";
		
		public function LicenceFile()
		{
		}
	}
}

<?xml version="1.0" encoding="utf-8"?>
<view:BaseSimpleContainer xmlns:fx="http://ns.adobe.com/mxml/2009" 
						  xmlns:s="library://ns.adobe.com/flex/spark" 
						  xmlns:mx="library://ns.adobe.com/flex/mx" 
						  xmlns:view="com.shine.framework.core.view.*" 
						  width="200" height="30" visible="false" creationComplete="{complete()}">
	<view:layout>
		<s:BasicLayout/>
	</view:layout>
	<fx:Script>
		<![CDATA[
			import com.shine.framework.Licence.LicenceManager;
			
			private function complete():void{
				this.completeLoading();
				
				LicenceManager.getInstance().loadLicence("data.swc",returnMethod);
			}
			
			private function returnMethod():void{
				this.visible=true;
			}
		]]>
	</fx:Script>
	<s:Label text="尊敬的客户,您的系统授权协议已经过期或者给非法盗用,为了保护您的利益,请与我们工程师联系!!" fontWeight="bold" fontStyle="italic" fontSize="12" />
</view:BaseSimpleContainer>

     单独这几个代码不是可以运行起来,主要代码还是要参阅我的flex的framework:

http://code.google.com/p/ken-javaframeword/source/browse/#svn%2Ftrunk%2Fframework2.0%2Fsrc%2Fcom%2Fshine%2Fframework%2FLicence



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值