有些朋友在开发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: