I am experiencing some issues using the TChilkatRSA class in Delphi; namely the basic Encrypt and Decrypt functions. I am attempting to encrypt a string, “This is a test”, using a generated key-pair. However, when I call the EncryptString, I get back nothing but multiple ‘?’. This leads into an issue where the decryption does not return the original value. I think that it has something to do with the conversion between charsets that the API documentation mentions. The EncryptStringENC and DecryptStringENC functions do not suffer from the same issue. I was hoping that you would have some debug suggestions to try to determine the actual cause of the “bad” encryption.
The EncryptString method will accept a string as input, but returns the binary encrypted bytes (not a string) as output. Encrypted bytes are indistinguishable from random binary byte data, where each byte can have a value from 0 to 255 (0x00 -- 0xFF). A character (visible glyph) is a sequence of one or more bytes interpreted according to a character encoding. For example:
Consider this character: É
In the iso-8859-1 character encoding, it is represented by a single byte: 0xC9
In the utf-8 character encoding, it is represented by a two bytes: 0xC3 0x89
In the ucs-2 character encoding, it is represented by a two bytes: 0x00 0xC9
When bytes are encountered that represent no displayable character (or the sequence makes no sense in the character encoding), then a program must either ignore the bytes or display a "?".