Note that there are some explanatory texts on larger screens.

plurals
  1. POPhp equivalent of as3crypto aes256-cbc
    primarykey
    data
    text
    <p>does anybody know what is the php equivalent of aes256-cbc cipher from as3crypto lib? I need to get the same result in as3 and php because my app requires as3 &lt;-> php data exchange.</p> <p><strong>Here is my as3 class:</strong> </p> <pre><code> 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='aes256-cbc'; private var key:ByteArray; public function CryptoCode() { init(); } private function init():void { key = Hex.toArray(Hex.fromString('secret'));// can only be 8 characters long //trace(encrypt('rower')); //trace(decrypt(encrypt('TEST TEST')); } public 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); } public function decrypt(txt:String = ''):String { var data:ByteArray = Base64.decodeToByteArray(txt); var pad:IPad = new PKCS5; var mode:ICipher = Crypto.getCipher(type, key, pad); pad.setBlockSize(mode.getBlockSize()); mode.decrypt(data); return Hex.toString(Hex.fromArray(data)); } } </code></pre> <p><strong>And php class</strong></p> <pre><code>class Crypt { var $key = NULL; var $iv = NULL; var $iv_size = NULL; function Crypt() { $this-&gt;init(); } function init($key = "") { $this-&gt;key = ($key != "") ? $key : ""; $this-&gt;algorithm = MCRYPT_DES; $this-&gt;mode = MCRYPT_MODE_ECB; $this-&gt;iv_size = mcrypt_get_iv_size($this-&gt;algorithm, $this-&gt;mode); $this-&gt;iv = mcrypt_create_iv($this-&gt;iv_size, MCRYPT_RAND); } function encrypt($data) { $size = mcrypt_get_block_size($this-&gt;algorithm, $this-&gt;mode); $data = $this-&gt;pkcs5_pad($data, $size); return base64_encode(mcrypt_encrypt($this-&gt;algorithm, $this-&gt;key, $data, $this-&gt;mode, $this-&gt;iv)); } function decrypt($data) { return $this-&gt;pkcs5_unpad(rtrim(mcrypt_decrypt($this-&gt;algorithm, $this-&gt;key, base64_decode($data), $this-&gt;mode, $this-&gt;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 &gt; strlen($text)) return false; if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false; return substr($text, 0, -1 * $pad); } </code></pre> <p>}</p> <p>It works properly with simple-des-ecb - Php and Flash outputs the same string but aes256-cbc gives different strings.</p> <p>I followed this example <a href="https://stackoverflow.com/questions/10471367/flash-encryption-php-decryption">Flash Encryption PHP Decryption</a> but I need aes265-cbc instead of simple-des-ecb.</p> <p>Can anyone help me?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload