开发者

exchange aes 256 encrypted data between php and flex

I need 2 sets of encrypt/decrypt functions to run under PHP and AS3.

I found AS3Crypto (for Flex) and mcrypt_encrypt (for PHP) and this article that shows 开发者_JAVA百科how to use them for DES encryption: http://www.zedia.net/2009/as3crypto-and-php-what-a-fun-ride/

I then tried to replace the DES encryption with AES-256, because the DES seems too vulnerable to brute force attacks. The results from AES encryption in Flex and PHP are different. Does anyone know (and tested) any equivalent functions for aes encryption in as3 and php?

If I wasn't clear enough, here is another post of an user having the same problem: http://forum.openlaszlo.org/showthread.php?t=13709

Thanks!


I've done similar with different back end's and it can be a headache to get them to match.

I will tell you with a high degree of confidence from experience that most likely the issue you're running into is that the padding isn't matching up between the two or the encoding going back and forth (Hex).

Here's some working coldfusion code from an implementation I did a couple years ago, quickest I could dig up...

<cfsetting enablecfoutputonly="yes">
<cfparam name="form.k" default="1bbee91984f8b5bc032b6f67a665704e"/>
<cfscript>
textToEncrypt = 'printButton=No&saveButton=No';
encKey = ToBase64(BinaryDecode(form.k,"Hex"));
encryptedText = encrypt(textToEncrypt, encKey, 'AES', 'Hex');
</cfscript>
<cfoutput>settings=#encryptedText#</cfoutput>

(side note: isnt coldfusion awesome? hehe :P)

The decryption side in flex :

private function settingsEncResponse( e : ResultEvent ) : void {
            // decrypt settings string
            var o : Object = e.result;
            var k:String = pKey; // key to decrypt with
            var kdata:ByteArray;
            kdata = Hex.toArray(k);
            var txt:String = o.settings; // text to decrypt
            var data:ByteArray;
            data = Hex.toArray(txt);
            var pad:IPad = new PKCS5;
            var mode:ICipher = Crypto.getCipher("aes-ecb", kdata, pad);
            pad.setBlockSize(mode.getBlockSize());
            mode.decrypt(data);
            currentInput = data;
            var decryptedSettings : String = Hex.toString(Hex.fromArray(currentInput)); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜