Why is CryptEncode() in mql4 different from other languages?

 

I was trying to understand CryptEncode() in order to send and receive strings between mt4 indicator and php server.

but When a string is encrypted on mql4 side its totally different then when its encrypted on the php side , same key and same encryption algorithm is used on both ends, but still the encryption is different on both sides 

And when i use an online tool to decrypt the php encrypted string it successfully decrypts the sting , whereas when i use the mql4 generated encrypted string it says final block is not properly padded.

Code: 

   string text="this is the text to be encoded";
   string keystr="d41d8cd98f00b204e9800998ecf8427e";
   uchar src[],dst[],key[];
    
    StringToCharArray(text,src);
    StringToCharArray(keystr,key);
    
       int encd=CryptEncode(CRYPT_AES256,src,key,dst);
       encd=CryptEncode(CRYPT_BASE64,dst,key,src);
       if(encd>0)
        {
          PrintFormat("Encoded data: size=%d, string='%s'",ArraySize(src),CharArrayToString(src));
        }
      else
         Print("Error in CryptEncode. Error code=",GetLastError());

Why is it that mql4 generated encrypted string different from a string generated by any other language ?
how to avoid this issue ?

and is there any alternative encryption library available to avoid this issue ?

Thank you 

 

I agree with you that the function is implemented with some limitations.

I had also expected to see CBC with an initial IV and  PKCS#5/7 padding.

Maybe in the future.

 
Marco vd Heijden:

I agree with you that the function is implemented with some limitations.

I had also expected to see CBC with an initial IV and  PKCS#5/7 padding.

Maybe in the future.

Jusy use StringToCharArray(text,src, 0, StringLen(src))
And the same also for the key to remove trailing zero from strings. 
Reason: