I tried to run your AES encryption examples with Delphi XE2.
encStr := CkCrypt2__encryptStringENC(crypt, 'The quick brown fox jumps over the lazy dog.');As long as the string to encrypt does contain normal ascii characters everything is OK.
But the input string is of type “pwidechar” so It can hold unicode characters.
If I change your example to
encStr := CkCrypt2__encryptStringENC(crypt, 'The quick brown fox jumps over the lazy dog.' + widechar(1602));The result is empty. Widechar(1602) is an Arabic letter.
How can I encrypt and decrypt strings containing Unicode ???
See the online reference documentation for EncryptStringENC:
Encryption algorithms work on bytes. The question is: What byte representation of the characters do you want to encrypt? Do you want to encrypt the ANSI character encoding? utf-8? or 2-byte/char Unicode? The Charset property controls this behavior. The default value of the Charset property is the ANSI charset, whatever it may be on the computer where your code is running. Given that you're not running on an Arabic computer, the ANSI charset is not going to be able to represent an Arabic character, and therefore the internal conversion from the Unicode string (passed from Delphi) to the ANSI byte representation fails, and the return value is empty. You can check the contents of the LastErrorText to confirm.
The solution is to set the Charset property equal to a charset that can handle the chars. "utf-8" is one possible choice. ("utf-8" is the multibyte encoding for Unicode.) You can also set the Charset property = "Unicode", or perhaps "Windows-1256" to handle single-byte/char us-ascii + Arabic.
Also, see this for more information: http://www.chilkatforum.com/questions/316/utf-8-characters-not-encrypting
answered Nov 14 '12 at 17:29