I need to provide the key as a hexadecimal string, password as string and finally i want the encrypted string to also be hexadecimal string.
This is covered in the Crypto++ wiki (there's lots of examples in there ready for copy/paste). From HexDecoder's Scripting and Strings:
On occasion, the mailing list will receive questions on cross-validation. For example, see AES CTR Chiper. Different output between PHP-mcrypt and Crypto++. In the question, PHP-mcrypt strings are used as follows:
$key = "1234567890123456789012345678901234567890123456789012345678901234"; $key = pack("H".strlen($key), $key); $iv = "1111111111222222222233333333334444444444555555555566666666667777"; $iv = pack("H".strlen($iv), $iv);
One of the easiest ways to avoid typos is via Copy/Paste and a HexDecoder:
string encodedKey = "1234567890123456789012345678901234567890123456789012345678901234"; string encodedIv = "1111111111222222222233333333334444444444555555555566666666667777"; string key, iv; StringSource ssk(encodedKey, true /*pumpAll*/, new HexDecoder( new StringSink(key) ) // HexDecoder ); // StringSource StringSource ssv(encodedIv, true /*pumpAll*/, new HexDecoder( new StringSink(iv) ) // HexDecoder ); // StringSource
After running the above code, key
and iv
are hexadecimal (i.e., binary) strings rather than printable (i.e., ASCII) strings.