How Posted February 23, 2020 Posted February 23, 2020 I use this Autolt function do encrypt my string.(example 2,I use AES-128 algorithm) https://www.autoitscript.com/autoit3/docs/libfunctions/_Crypt_EncryptData.htm it work well for decrypt and encrypt in Autolt. But,I want to encrypt in Autolt and decrypt that in C++. I try this code,but it didn't work(result is wrong). string Decrypt_string(char* Key, string HEX_Message, int size) { static const char* const lut = "0123456789ABCDEF"; int i = 0; char* Res; AES_KEY dec_key; string auxString, output, newString; for (i = 0; i < size; i += 2) { string byte = HEX_Message.substr(i, 2); char chr = (char)(int)strtol(byte.c_str(), NULL, 16); auxString.push_back(chr); } const char* Msg = auxString.c_str(); Res = (char*)malloc(size); AES_set_decrypt_key((unsigned char*)Key, 128, &dec_key); for (i = 0; i <= size; i += 16) { AES_ecb_encrypt((unsigned char*)Msg + i, (unsigned char*)Res + i, &dec_key, AES_DECRYPT); } output.reserve(2 * size); for (size_t i = 0; i < size; ++i) { const unsigned char c = Res[i]; output.push_back(lut[c >> 4]); output.push_back(lut[c & 15]); } int len = output.length(); cout << output << endl; for (int i = 0; i < len; i += 2) { string byte = output.substr(i, 2); char chr = (char)(int)strtol(byte.c_str(), NULL, 16); newString.push_back(chr); } free(Res); return newString; }
TheDcoder Posted November 2, 2020 Posted November 2, 2020 Have you taken the character encoding into consideration? AutoIt uses UTF-16 LE, WinAPI's default unicode encoding, from the looks of your code you are using plain chars... try using wchar and see if it makes a difference. EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now