decrypt a as3crypto encrypted text in PHP

后端 未结 2 855
星月不相逢
星月不相逢 2021-01-16 12:04

i tried to encrypt a text in as3crypto via the demo app.

now i am trying to decrypt the crypted text via php but it seems that the text is not properly decrypted. ha

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-16 13:06

    This would work:

    PHP code:

    //notice that $key and $iv length must be 16 chars long! ex: 1234567890123456
    function decrypt($data,$key,$iv)
    {
    
        $decr= mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($data), MCRYPT_MODE_CBC, $iv);    
        return $decr;   
    }
    

    And here is AS3 code

    //notice that $key and $iv length must be 16 chars long! ex: 1234567890123456
    private function encrypt(input:String,decrKey:String,decrIV:String):String
    {
        var inputBA:ByteArray=Hex.toArray(Hex.fromString(input));        
        var key:ByteArray = Hex.toArray(Hex.fromString(decrKey));                
        var pad:IPad = new NullPad();
        var aes:ICipher = Crypto.getCipher("aes-cbc", key, pad);
        var ivmode:IVMode = aes as IVMode;
        ivmode.IV = Hex.toArray(Hex.fromString(decrIV));            
        aes.encrypt(inputBA);  
    
        return Base64.encodeByteArray( inputBA);
    }       
    

提交回复
热议问题