来自:http://blog.ityao.com/archives/677
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.utils.Base64Decoder;
import mx.utils.Base64Encoder;
protected function btnEncode_clickHandler(event:MouseEvent):void{
var $orgin:String = this.textOrigi.text;//获取原始字符串
var $base64:Base64Encoder = new Base64Encoder();
$base64.insertNewLines = false;//该值等于true时,输出的结果会自动换行,默认为true,
$base64.encodeUTFBytes($orgin);//这里注意,如果想加密中文就不要使用$base64.encode();
var $result:String = $base64.toString();//输出结果
this.textEncodeResult.text = $result
}
protected function btnDecode_clickHandler(event:MouseEvent):void{
var $origi:String = this.textEncodeResult.text;//获取原始字符串
var $base64:Base64Decoder = new Base64Decoder();
$base64.decode($origi);
var $result:String = $base64.toByteArray().toString();//输出结果,decode类只能输出ByteArray类型的数据,因此要转换成string
this.textDecodeResult.text = $result
}
]]>
</fx:Script>
<mx:Form width="100%">
<mx:FormItem label="原始字符串:" width="100%">
<s:TextArea editable="true" id="textOrigi" width="100%" text="在这里输入原始字符串"/>
</mx:FormItem>
<mx:FormItem>
<s:Button id="btnEncode" label="Encode Base64" enabled="{this.textOrigi.text!=''}" click="btnEncode_clickHandler(event)"/>
</mx:FormItem>
<mx:FormItem label="Encode 结果:" width="100%">
<s:TextArea editable="false" id="textEncodeResult" width="100%"/>
</mx:FormItem>
<mx:FormItem>
<s:Button id="btnDecode" enabled="{this.textEncodeResult.text!=''}" label="Decode Base64" click="btnDecode_clickHandler(event)"/>
</mx:FormItem>
<mx:FormItem label="Decode 结果:" width="100%">
<s:TextArea editable="false" id="textDecodeResult" width="100%" text="点击Decode Base64按钮后,这里的结果应该和原始字符串相同"/>
</mx:FormItem>
</mx:Form>
</s:Application>
友情链接:珀莱雅 欧诗漫 专卖 [url]http://store.taobao.com/shop/view_shop.htm?mytmenu=mdianpu&utkn=g,2djlrizuga4a1324992712104&user_number_id=372143050[/url]
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.utils.Base64Decoder;
import mx.utils.Base64Encoder;
protected function btnEncode_clickHandler(event:MouseEvent):void{
var $orgin:String = this.textOrigi.text;//获取原始字符串
var $base64:Base64Encoder = new Base64Encoder();
$base64.insertNewLines = false;//该值等于true时,输出的结果会自动换行,默认为true,
$base64.encodeUTFBytes($orgin);//这里注意,如果想加密中文就不要使用$base64.encode();
var $result:String = $base64.toString();//输出结果
this.textEncodeResult.text = $result
}
protected function btnDecode_clickHandler(event:MouseEvent):void{
var $origi:String = this.textEncodeResult.text;//获取原始字符串
var $base64:Base64Decoder = new Base64Decoder();
$base64.decode($origi);
var $result:String = $base64.toByteArray().toString();//输出结果,decode类只能输出ByteArray类型的数据,因此要转换成string
this.textDecodeResult.text = $result
}
]]>
</fx:Script>
<mx:Form width="100%">
<mx:FormItem label="原始字符串:" width="100%">
<s:TextArea editable="true" id="textOrigi" width="100%" text="在这里输入原始字符串"/>
</mx:FormItem>
<mx:FormItem>
<s:Button id="btnEncode" label="Encode Base64" enabled="{this.textOrigi.text!=''}" click="btnEncode_clickHandler(event)"/>
</mx:FormItem>
<mx:FormItem label="Encode 结果:" width="100%">
<s:TextArea editable="false" id="textEncodeResult" width="100%"/>
</mx:FormItem>
<mx:FormItem>
<s:Button id="btnDecode" enabled="{this.textEncodeResult.text!=''}" label="Decode Base64" click="btnDecode_clickHandler(event)"/>
</mx:FormItem>
<mx:FormItem label="Decode 结果:" width="100%">
<s:TextArea editable="false" id="textDecodeResult" width="100%" text="点击Decode Base64按钮后,这里的结果应该和原始字符串相同"/>
</mx:FormItem>
</mx:Form>
</s:Application>
友情链接:珀莱雅 欧诗漫 专卖 [url]http://store.taobao.com/shop/view_shop.htm?mytmenu=mdianpu&utkn=g,2djlrizuga4a1324992712104&user_number_id=372143050[/url]