Flex——DES加密解密

使用开源项目as3crypto

http://code.google.com/p/as3crypto/

 

为了方便调用,写个工具类CryptoUtil

package crypto

{

       import com.hurlant.crypto.symmetric.DESKey;

      

       import flash.utils.ByteArray;

      

       import mx.utils.Base64Decoder;

       import mx.utils.Base64Encoder;

 

       public final class CryptoUtil

       {

 

              public static function DESEncrypt(src:String,k:String):String

              {

                     var key:ByteArray = new ByteArray();

                     key.writeUTFBytes(k);

                    

                     var bytes:ByteArray = new ByteArray();

                     bytes.writeUTFBytes(src);

                    

                     var des:DESKey = new DESKey(key);

                     des.encrypt(bytes);

        

                     varbase64:Base64Encoder = newBase64Encoder();

                     base64.encodeBytes(bytes);

                     return base64.flush();

              }

             

              public static function DESDecrypt(src:String,k:String):String

              {

                     var key:ByteArray = new ByteArray();

                     key.writeUTFBytes(k);

                    

                     varbase64:Base64Decoder = newBase64Decoder();

                     base64.decode(src);

                    

                     var bytes:ByteArray = base64.toByteArray();

                     var des:DESKey = new DESKey(key);

                     des.decrypt(bytes);

                    

                     bytes.position = 0;

                     return bytes.readUTFBytes(bytes.length);

              }

             

       }

}

 

测试代码

                           var str:String = crypto.CryptoUtil.DESEncrypt("hlib收到了是浪费空间啊未来人口仅为上的浪费空间","hlib123");

                           trace(str);

                           str = crypto.CryptoUtil.DESDecrypt(str, "hlib123");

                           trace(str);

 

 

测试输出

jhkCY7Xlk+WIsOS6huaYr+a1qui0ueepuumXtOWViuacquadpeS6uuWPo+S7heS4uuS4iueahOa1

qui0ueepuumXtA==

hlib收到了是浪费空间啊未来人口仅为上的浪费空间

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值