as3 php md5,Flash加密PHP解密

对于Flash,它可以支持

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

> RSA

> DES

> AES

>河豚 –

> MD5

> SHA

> X509

> RC4

PHP你可以使用mycrypt http://www.php.net/manual/en/mcrypt.examples.php RSA,DES,AES,Blowfish,MD5,SHA,X509,RC4以上加密也支持

Flash类示例

package

{

import flash.display.Sprite;

import flash.utils.ByteArray;

import com.hurlant.crypto.symmetric.ICipher;

import com.hurlant.crypto.symmetric.IVMode;

import com.hurlant.crypto.symmetric.IMode;

import com.hurlant.crypto.symmetric.NullPad;

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;

public class CryptoCode extends Sprite

{

private var type:String='simple-des-ecb';

private var key:ByteArray;

public function CryptoCode()

{

init();

}

private function init():void

{

key = Hex.toArray(Hex.fromString('TESTTEST'));// can only be 8 characters long

trace(encrypt('TEST TEST'));

trace(decrypt(encrypt('TEST TEST'));

}

private function encrypt(txt:String = ''):String

{

var data:ByteArray = Hex.toArray(Hex.fromString(txt));

var pad:IPad = new PKCS5;

var mode:ICipher = Crypto.getCipher(type,key,pad);

pad.setBlockSize(mode.getBlockSize());

mode.encrypt(data);

return Base64.encodeByteArray(data);

}

private function decrypt(txt:String = ''):String

{

var data:ByteArray = Base64.decodeToByteArray(txt);

var pad:IPad = new PKCS5;

var mode:ICipher = Crypto.getCipher(type,pad);

pad.setBlockSize(mode.getBlockSize());

mode.decrypt(data);

return Hex.toString(Hex.fromArray(data));

}

}

}

PHP类示例

class Crypt

{

var $key = NULL;

var $iv = NULL;

var $iv_size = NULL;

function Crypt()

{

$this->init();

}

function init($key = "")

{

$this->key = ($key != "") ? $key : "";

$this->algorithm = MCRYPT_DES;

$this->mode = MCRYPT_MODE_ECB;

$this->iv_size = mcrypt_get_iv_size($this->algorithm,$this->mode);

$this->iv = mcrypt_create_iv($this->iv_size,MCRYPT_RAND);

}

function encrypt($data)

{

$size = mcrypt_get_block_size($this->algorithm,$this->mode);

$data = $this->pkcs5_pad($data,$size);

return base64_encode(mcrypt_encrypt($this->algorithm,$this->key,$data,$this->mode,$this->iv));

}

function decrypt($data)

{

return $this->pkcs5_unpad(rtrim(mcrypt_decrypt($this->algorithm,base64_decode($data),$this->iv)));

}

function pkcs5_pad($text,$blocksize)

{

$pad = $blocksize - (strlen($text) % $blocksize);

return $text . str_repeat(chr($pad),$pad);

}

function pkcs5_unpad($text)

{

$pad = ord($text{strlen($text)-1});

if ($pad > strlen($text)) return false;

if (strspn($text,chr($pad),strlen($text) - $pad) != $pad) return false;

return substr($text,-1 * $pad);

}

}

用法闪光

// instance of crypto class

private var _crypto : CryptoCode;

public var myLoader : URLLoader;

// create instance with encryption key

_crypto = new CryptoCode("PASSWORD");

// send crypted string to PHP script

var variables : URLVariables = new URLVariables();

variables.message = _crypto.encrypt(tosend_in.text);

// create request with POST method

var request : URLRequest = new URLRequest("http://www.lecrabe.net/wordpress/demo/crypt/scripts/testcrypto.PHP");

request.method = URLRequestMethod.POST;

request.data = variables;

// send request

myLoader.load(request);

include_once "lib/cryptlib.PHP";

// init a new instance of Crypto Class

$crypto = new Crypt;

// init with the encryption key

$result = $crypto->init("PASSWORD");

// get the POST data

$messagefromflash = $_POST ["message"];

// decrypt data

$decrypted_messagefromflash = $crypto->decrypt(utf8_decode($messagefromflash));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值