[AS3]as3下用Crypto做的DES加密算法与解密算法源代码
[AS3]as3下用Crypto做的DES加密算法与解密算法
Crypto库 http://code.google.com/p/as3crypto/
- package
- {
- import com.hurlant.crypto.Crypto;
- import com.hurlant.util.Hex;
- import com.hurlant.crypto.hash.HMAC;
- import com.hurlant.crypto.hash.IHash;
- import com.hurlant.crypto.hash.MD5;
- import com.hurlant.crypto.hash.SHA1;
- import com.hurlant.crypto.hash.SHA224;
- import com.hurlant.crypto.hash.SHA256;
- import com.hurlant.crypto.prng.ARC4;
- import com.hurlant.crypto.symmetric.AESKey;
- import com.hurlant.crypto.symmetric.BlowFishKey;
- import com.hurlant.crypto.symmetric.CBCMode;
- import com.hurlant.crypto.symmetric.CFB8Mode;
- import com.hurlant.crypto.symmetric.CFBMode;
- import com.hurlant.crypto.symmetric.CTRMode;
- import com.hurlant.crypto.symmetric.DESKey;
- import com.hurlant.crypto.symmetric.ECBMode;
- import com.hurlant.crypto.symmetric.ICipher;
- import com.hurlant.crypto.symmetric.IMode;
- import com.hurlant.crypto.symmetric.IPad;
- import com.hurlant.crypto.symmetric.ISymmetricKey;
- import com.hurlant.crypto.symmetric.IVMode;
- import com.hurlant.crypto.symmetric.NullPad;
- import com.hurlant.crypto.symmetric.OFBMode;
- import com.hurlant.crypto.symmetric.PKCS5;
- import com.hurlant.crypto.symmetric.SimpleIVMode;
- import com.hurlant.crypto.symmetric.TripleDESKey;
- import com.hurlant.crypto.symmetric.XTeaKey;
- import flash.utils.ByteArray;
- import com.hurlant.crypto.rsa.RSAKey;
- import com.hurlant.util.Base64;
- public class BlowFish
- {
- /**
- * Encrypts a string.
- * @param text The text string to encrypt.
- * @param key A cipher key to encrypt the text with.
- */
- /**
- * Decrypts an encrypted string.
- * @param text The text string to decrypt.
- * @param key The key used while originally encrypting the text.
- */
- static public function encrypt( s :String, k :String ) :String
- {
- var key :ByteArray = Hex.toArray(k);
- var data :ByteArray = Hex.toArray(Hex.fromString(s));
- var pad :IPad = new NullPad();
- var cipher :ICipher = Crypto.getCipher("blowfish-cbc", key, pad);
- pad.setBlockSize(cipher.getBlockSize());
- cipher.encrypt(data);
- var result :String = Hex.fromArray(data);
- var ivmode :IVMode = cipher as IVMode;
- var iv :String = Hex.fromArray(ivmode.IV);
- return Base64.encodeByteArray(Hex.toArray(Hex.fromArray(ivmode.IV) + Hex.fromArray(data)));
- }
- }
- }
应用
- import BlowFish;
- var $key:String = "12345678";
- var $encryption:String = BlowFish.encrypt("cuplayer.com", $key);
- trace( $encryption );
Crypto做的DES加密算法与解密算法
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...