What are the outputs ?
Hello Alain,
I will do more tests with it and try some other libs. But checking some documentation from Crypto nodejs we have:
crypto.createCipher(algorithm, password)
It says: "The password is used to derive the cipher key and initialization vector (IV). The value must be either a 'latin1' encoded string, a Buffer, a TypedArray, or a DataView"
and
crypto.createCipheriv(algorithm, key, iv)
The second one accepts a key and IV
What about CryptEncode() not using IV? Maybe it generates an IV itself? I really don't have this answer right now.
Key and IV are a common argument among other language libs for AES256.
I will do some tests with cryptojs and a C code for AES256.
Let's see what happens.
Thank you!
- nodejs.org
Hello Alain,
I will do more tests with it and try some other libs. But checking some documentation from Crypto nodejs we have:
crypto.createCipher(algorithm, password)
It says: "The password is used to derive the cipher key and initialization vector (IV). The value must be either a 'latin1' encoded string, a Buffer, a TypedArray, or a DataView"
and
crypto.createCipheriv(algorithm, key, iv)
The second one accepts a key and IV
What about CryptEncode() not using IV? Maybe it generates an IV itself? I really don't have this answer right now.
Key and IV are a common argument among other language libs for AES256.
I will do some tests with cryptojs and a C code for AES256.
Let's see what happens.
Thank you!
Hi folks,
A litle late to answer, but...
I faced exactly the same problem, my application and my EA was not creating the same encrypted code, due to the lack of information, I made a big research (also try and error) and after a lot of effort I discovered the configuration used by MetaQuotes in the CryptEncode() and CryptDecode() functions.
My code is made in C#, but it is easy to read and understand.
Note 1: in AES-128 the key maximum size is 16 bytes, if the size is minor then 16, fill the remaining bytes with zeros;
Note 2: in DES the key maximum size is 8, if the size is minor then 8, fill the remaining bytes with zeros and the last byte must be zero too.
Note 3: in DES the size of the text must be multiple of 8 with the extra bytes filled by zero;
Configuration for AES-128 (C# code):
byte[] arrKey = Encoding.UTF8.GetBytes(key); if (arrKey.Length != 16) Array.Resize(ref arrKey, 16); using (Aes aesAlg = Aes.Create()) { aesAlg.Mode = CipherMode.ECB; aesAlg.Padding = PaddingMode.Zeros; aesAlg.BlockSize = 128; aesAlg.KeySize = 128; aesAlg.Key = arrKey; aesAlg.IV = new byte[16];
Configuration for DES (C# code):
// Encode and check message and password byte[] arrText = Encoding.UTF8.GetBytes(originalString); byte[] arrKey = Encoding.UTF8.GetBytes(keyString); if (arrKey.Length != 8) Array.Resize(ref arrKey, 8); arrKey[7] = 0; if (arrText.Length % 8 == 0) Array.Resize(ref arrText, arrText.Length + 8); // Set encryption settings DESCryptoServiceProvider provider = new DESCryptoServiceProvider(); provider.Mode = CipherMode.ECB; provider.Padding = PaddingMode.Zeros; provider.BlockSize = 64; provider.KeySize = 64; provider.Key = arrKey; provider.IV = new byte[8];
I expect this can help others.
Hi folks,
A litle late to answer, but...
I faced exactly the same problem, my application and my EA was not creating the same encrypted code, due to the lack of information, I made a big research (also try and error) and after a lot of effort I discovered the configuration used by MetaQuotes in the CryptEncode() and CryptDecode() functions.
My code is made in C#, but it is easy to read and understand.
Note 1: in AES-128 the key maximum size is 16 bytes, if the size is minor then 16, fill the remaining bytes with zeros;
Note 2: in DES the key maximum size is 8, if the size is minor then 8, fill the remaining bytes with zeros and the last byte must be zero too.
Note 3: in DES the size of the text must be multiple of 8 with the extra bytes filled by zero;
Configuration for AES-128 (C# code):
Configuration for DES (C# code):
I expect this can help others.
Hi folks,
A litle late to answer, but...
I faced exactly the same problem, my application and my EA was not creating the same encrypted code, due to the lack of information, I made a big research (also try and error) and after a lot of effort I discovered the configuration used by MetaQuotes in the CryptEncode() and CryptDecode() functions.
My code is made in C#, but it is easy to read and understand.
Note 1: in AES-128 the key maximum size is 16 bytes, if the size is minor then 16, fill the remaining bytes with zeros;
Note 2: in DES the key maximum size is 8, if the size is minor then 8, fill the remaining bytes with zeros and the last byte must be zero too.
Note 3: in DES the size of the text must be multiple of 8 with the extra bytes filled by zero;
Configuration for AES-128 (C# code):
Configuration for DES (C# code):
I expect this can help others.
Thanks for sharing it! :)

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm wondering if anyone tried some comparisons with CryptEncode() MQL5 function and Crypto Nodejs library and get the same encrypted cipher.
So far I´ve tried Crypto Nodejs with these methods:
For CryptEncode() MQL5 function:
None of this tests resulted in the same encrypted cipher for both CryptEncode() and Crypto Nodejs.
On the other hand, if you try SHA512+HMAC library example and then try with Crypto Nodejs, you get the same cipher.
MQL5 code for DES:
MQL5 code for AES256 using Bcrypt library:
Nodejs code for AES/DES:
Methods could be changed by swapping 'des' for the desired method listed above.
Nodejs code for SHA512+HMAC:
If someone wants to test nodejs code, it's possible to do it online at repl.it
Now I´m wondering if there is nothing wrong with CryptEncode() MQL5 function as the ciphers should be matched.
Any idea would be appreciated!
Best regards,
Romeu.