why is CryptDecode not Working ?

 

I am trying to decode an encrypted string (Encryption was done using php )

String was encrypted using AES-256-ECB  with Padding mode as Zeros.
and and if i encrypt the string in the mql4 using the same key , i get exact same encrypted string as the one  i get from php.

initially i was struggling to get the same encrypted string but finally managed to generate the same encrypted string on both sides

but now CryptDecode is causing issues:

   string   text        =     "ke6vXGoxARG3QbczfdX5pQbVFidy+PBkHCITUOP94vXtFLOm/VmSLRHEU1CRqNoUbarkcroOLhZ4Oc/iApZq/g==";
   string   keystr      =     "1234567890asdfghjkloiuytrewqzxcv";
   
   uchar src[] ,  dst[] ,  key[] ,  sec[];
   StringToCharArray(   text     ,  src );
   StringToCharArray(   keystr   ,  key ); 
   int   res   =  CryptDecode(   CRYPT_BASE64   ,  src   ,  key   ,  dst   );
         res   =  CryptDecode(   CRYPT_AES256   ,  dst   ,  key   ,  sec); 
         PrintFormat("Decoded data: size=%d, string='%s'",ArraySize(sec),CharArrayToString(sec));
         Print(GetLastError());

I am getting :

Error:  4029
Decoded data: size=0, string=''


Any advice regarding this issue ?

 
Use StringToCharArray with explicit count parameter to exclude terminal zero from the resulting byte array.

StringToCharArray(text, src, 0, StringLen(text)) ;

 
amrali:
Use StringToCharArray with explicit count parameter to exclude terminal zero from the resulting byte array.


@amrali Thank you it solved the problem  , encryption/decryption in mql4 is really messing with my head , its so much simpler in python and php and other languages but quite a bit of limitations in mql4
 
amrali #:
Use StringToCharArray with explicit count parameter to exclude terminal zero from the resulting byte array.


thanks....
Reason: