Consultor Eletrônico



Kbase P139555: Encrypted data can not be decrypted after being passed as CHARACTER data
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   25/05/2011
Status: Verified

SYMPTOM(s):

Data is encrypted using the ENCRYPT function

Resulting MEMPTR is moved to CHARACTER variable using GET-STRING function

After converting CHARACTER variable back to MEMPTR the data cannot be decrypted succesfully

DECRYPT error (14272)

error (14272)

FACT(s) (Environment):

OpenEdge 10.0B
OpenEdge 10.1x
OpenEdge 10.2x
All Supported Operating Systems
OpenEdge Category: Language (4GL/ABL)

CAUSE:

This is expected behavior.

1. The MEMPTR returned by ENCRYPT contains bytes that can have any value, including NUL (0x00).
Depending on the exact contents of the MEMPTR and the character codepage used, this means that the binary data may contain string terminators and/or invalid characters for the codepage used.
This causes the GET-STRING function to fail with errors or to return only the part of the data before the first string terminator.

2. If the PUT-STRING function is used to convert the character back to a MEMPTR this function will add a NULL terminator to the character string unless the number of bytes to write is specified.
This additional NULL terminator corrupts the data in it's encrypted format and will also cause the decryption to fail.

If only part of the data is fetched into the CHARACTER variable, when it is passed back through the DECRYPT function that function either fails with an error, or returns incorrect data.

FIX:

To avoid issues when passing binary data as a CHARACTER string, use base64 encoding to store it into a CHARACTER variable.