Download MetaTrader 5

Decrypt

To add comments, please log in or register
Gordon Gekko
623
Gordon Gekko 2015.12.22 21:21 

Hi Gurus!

Here is the mql example of using of CryptEncode/CryptDecode.

Based on that example, let's say:

string my_string=ArrayToHex(dst);


I'd like to get the original text string ("The quick brown ... ") from my_string.

How can I get it?

Thank you 
honest_knave
Moderator
2395
honest_knave 2015.12.23 12:54  

It would be easier to just decrypt dst[] (from which you made my_string), rather than try to decrypt my_string.

If you try to push my_string back into a uchar array using StringToCharArray() then run it through CryptDecode() you'll get an invalid array error code.

So, I'm not sure what the answer would be (other than stick to decrypting dst). 

Gordon Gekko
623
Gordon Gekko 2015.12.23 13:48  
honest_knave:

It would be easier to just decrypt dst[] (from which you made my_string), rather than try to decrypt my_string.

If you try to push my_string back into a uchar array using StringToCharArray() then run it through CryptDecode() you'll get an invalid array error code.

So, I'm not sure what the answer would be (other than stick to decrypting dst). 

Hi honest_knave, thank you for your answer. Yes, I know it would be easy to decrypt dst[], but I have to use my_string, it is important.
Gatoreye
66
Gatoreye 2015.12.23 17:13  
You defeat the purpose of encryption if you were able to simply convert Hex back to Binary. If you try to do that, you will lose the encryption rule built into dst[] so that the string would be useless. The function ArrayToHex() is there to show this gibberish binary data in human readable characters, and is nothing more than that. The only way to convert it to the original text is to decrypt dst[]. Why don't you simply save off dst[] to a file, and then decrypt it when you need it?
Gordon Gekko
623
Gordon Gekko 2015.12.23 17:31  
gatoreyefx:
You defeat the purpose of encryption if you were able to simply convert Hex back to Binary. If you try to do that, you will lose the encryption rule built into dst[] so that the string would be useless. The function ArrayToHex() is there to show this gibberish binary data in human readable characters, and is nothing more than that. The only way to convert it to the original text is to decrypt dst[]. Why don't you simply save off dst[] to a file, and then decrypt it when you need it?

This was my goal: encoding some information into the my_string (for example expiration date, etc ..) and getting back this information for the program (expert, indi) from the my_string.

I give my_string to the user, he/she has to use it as an input for the program, and the program can check whether the using of it is valid or not.

I cannot give dst[] to the user. ;)

Gatoreye
66
Gatoreye 2015.12.23 18:17  
Then give the hex string to the user. You will save off the encoded dst[] to somewhere you only know.  When the user inputs the hex string, decrypt and convert your dst[] to hex, and then compare that hex to the user's hex input. If both matches, you can tell whether it is valid or not. How about that?
Gordon Gekko
623
Gordon Gekko 2015.12.23 18:47  

1./ Maybe I'm wrong, but I think hex string is my_string, isn't it? Remember >>

string my_string=ArrayToHex(dst);

2./ Anyway it is not good. I want encode expiration date into the hex string (my_string). So, I need to decode this date from the hex string (my_string) and the program examines this date for validation.

Gatoreye
66
Gatoreye 2015.12.23 19:41  
Your user will never know what's in the hex string even if he/she can convert it to binary unless he/she knows the key to decrypt this. You are the only one who will be able to decrypt this because you have the key. You see, dst[] has both your data and key encrypted into it in a special format. Hex does not mean a thing. It just shows a bunch of readable characters. That's all. You need to build in some mechanism to save off dst[] and decrypt it in order to compare it to user input. I do not think you can convert the hex directly to dst[] and decrypt it, even if you know the key, because the hex string does not remember the special format when encrypted.
Gordon Gekko
623
Gordon Gekko 2015.12.23 20:20  

I understand and agree with these, but there is one thing:

You wrote this: "You need to build in some mechanism to save off dst[]"

This is not clear to me, how can I do this? What do you mean? Can you explain it? Thank you

Gatoreye
66
Gatoreye 2015.12.23 20:30  
Maybe, it is better for you to elaborate in detail what you are trying to accomplish with encryption and decryption.
Gordon Gekko
623
Gordon Gekko 2015.12.23 20:45  
gatoreyefx:
Maybe, it is better for you to elaborate in detail what you are trying to accomplish with encryption and decryption.

Just as I wrote, I make a string that contains encoded expiration date. I give this string to the user who inputs this to the expert. Expert checks (decodes) this string for validation.

(With this method no need to hardcode the exp date into the code itself.)

123
To add comments, please log in or register