积少成多Flash(12) - Flex 3.0 验证控件(Validator), 缓动效果(easing)
2009-11-28 00:00:00 来源:WEB开发网7、Encyption3DES.mxml
<?xml version="1.0" encoding="utf-8"?>
<!--
用 AS3 封装好的常用加密算法。详情 http://crypto.hurlant.com
以下以 3DES 加密/解密为例
-->
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
title="3DES - ECB 加密解密算法 Demo" width="424" height="382">
<mx:Script>
<![CDATA[
import com.hurlant.crypto.symmetric.ICipher;
import com.hurlant.crypto.symmetric.PKCS5;
import com.hurlant.crypto.symmetric.IPad;
import com.hurlant.util.Base64;
import com.hurlant.util.Hex;
import com.hurlant.crypto.Crypto;
private function encryptHandler():void
{
var key:String = txtKey.text;
var keyData:ByteArray = Hex.toArray(Hex.fromString(key));
var plain:String = txtPlainText.text;
var plainData:ByteArray = Hex.toArray(Hex.fromString(plain));
var name:String = "des3-ecb";
var pad:IPad = new PKCS5;
var mode:ICipher = Crypto.getCipher(name, keyData, pad);
pad.setBlockSize(mode.getBlockSize());
mode.encrypt(plainData);
var result:String = Base64.encodeByteArray(plainData);
txtCipherText.text = result;
}
private function decryptHandler():void
{
var key:String = txtKey.text;
var keyData:ByteArray = Hex.toArray(Hex.fromString(key));
var cipher:String = txtCipherText.text;
var cipherData:ByteArray = Base64.decodeToByteArray(cipher);;
var name:String = "des3-ecb";
var pad:IPad = new PKCS5;
var mode:ICipher = Crypto.getCipher(name, keyData, pad);
pad.setBlockSize(mode.getBlockSize());
mode.decrypt(cipherData);
var result:String = Hex.toString(Hex.fromArray(cipherData));
txtPlainText.text = result;
}
]]>
</mx:Script>
<mx:Label text="加密结果以 Base64 编码输出" x="10" y="10"/>
<mx:Button x="286" y="184" label="加密" id="btnEncrypt" click="encryptHandler()"/>
<mx:Button x="342" y="184" label="解密" id="btnDecrypt" click="decryptHandler()"/>
<mx:TextInput x="53" y="34" width="337" id="txtKey" text="#s^un2ye31<cn%|aoXpR,+vh"/>
<mx:Label x="10" y="36" text="密钥:"/>
<mx:TextInput x="10" y="88" width="380" height="88" id="txtPlainText"/>
<mx:TextInput x="10" y="240" width="380" height="88" id="txtCipherText"/>
<mx:Label x="10" y="62" text="原文: "/>
<mx:Label x="10" y="214" text="密文: "/>
</mx:Panel>
8、Other.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
<mx:Label text="懒了,Flex 还有好多东西啊,不过暂时先到这里吧"/>
<mx:Label text="SoundEffect 用于播放声音"/>
<mx:Label text="VideoDisplay 用于播放视频"/>
<mx:Label text="调用 Flash 开发的 swc 组件时,一般将其放入 libs 目录内"/>
<mx:Label text="减小主 Flex 程序的大小,可以把子模块写成 Module(被编译成独立的 swf) ,然后在需要的时候加载"/>
<mx:Label text="编译 Flex 的两种方式:Merged into code;Runtime shared library (RSL)"/>
</mx:VBox>
本文源代码下载地址: http://flashview.ddvip.com/2009_11/Flash.rar
- ››FLASH不等于运算符!=的使用实例
- ››FLASH不全等运算符!==
- ››FLASH字符串分隔符运算符
- ››FLASH% 模运算符
- ››Flash+、++、+= 加法运算符
- ››Flash, 逗号运算符
- ››flash中的-、--、-=减法运算符
- ››Flash的-Infinity 常数、.点运算符、/ 除法运算符...
- ››Flash两种注释方法/*..*/ 和// 注释行分隔符运算符...
- ››Flash的/=除法赋值运算符、=赋值运算符、== 等于运...
- ››Flash之?: 条件运算符、^ 按位 XOR 运算符、^= 按...
- ››Flash的_framesloaded代码示例
更多精彩
赞助商链接