Frequently asked questions – Encryption

I cannot decrypt encrypted data which I saved to a file, what can be the problem ?

The most common reason for that is when users have attempted to save
encrypted data into a text file. Saving encrypted data to a text file does not work because encrypted data can contain any symbol, including control symbols for text files such as Chr(13).

When saving encrypted data then it either has to be saved into a
BinaryStream or if its supposed to go into a Text file or other text media
then it has to be encoded to HEX format or Base64.

I cannot decrypt data that was encrypted on other machine, what can be the problem ?

1. Verify that the problem is not because of saving the data into a Text based container. (See the above).

2. Encrypted data is by nature binary data, which means that you may never ever put a text encoding or attempt to do any text encoding conversion on it. Verify that your Application does not assume it is text by putting encoding on it.

3. Encryption keys are considdered to be binary data. This means that the Key “Hello World” may not be the same as the Key “Hello World”. However if you have explicitly defined the encoding of both “Hello World” to the same then “Hello World” is the same key as “Hello World”.

When I encrypt text then European characters get lost when I decrypt it,
what am I doing wrong ?

Encryption is on binary level, it only takes raw bytes and encrypts them.
The info on what encoding your text was is not a part of the raw bytes. This means that you are responsible for saving and restoring the encoding if you are working with text where you want to preserve encodings.

Here is how it should be done:

1. Save the Encoding of the text that you are about to Encrypt.
2. Encrypt the text. (Remember once it is in encrypted form then you may never ever tamper with the encoding).

1. Decrypt the data.
2. Restore the encoding by using DefineEncoding (*not ConvertEncoding)

* DefineEncoding because you are not actually going to convert, the bytes are allready all correct it is just it does not know what encoding it is, so by using DefineEncoding then we promise that the bytes are actually what you say the are.

Einhugur technical blog that involves Xojo and Einhugur Xojo plugin related topics

%d bloggers like this: