0

I need help. I ENCRYPT json packages with our clients' data with AES_CBC_256 and a different key for each package. Out of about a million data packets generated, the first several dozen cannot be DECRYPT, which returns "?" Subsequent data packets are properly encrypted and can be decrypted properly. MEMPTR is extended by data size + 1024 bytes. The package is first encrypted and then encoded Base64. I do not use IV. The code below is devoid of all error handling for better readability. Any suggestions?

FUNCTION {&Modul}-encrypt RETURN CHAR(INPUT pInput AS LONGCHAR, INPUT pKey AS RAW, OUTPUT pOut AS LONGCHAR).
  DEF VAR mMemPtr AS MEMPTR NO-UNDO.
  FIX-CODEPAGE(pOut) = "UTF-8".
  
  SECURITY-POLICY:SYMMETRIC-ENCRYPTION-ALGORITHM = "AES_CBC_256".
  SECURITY-POLICY:SYMMETRIC-ENCRYPTION-KEY = pkey.
  
  SET-SIZE(mMemPtr) = LENGTH(pInput) + 1024.
  
  mMemPtr = ENCRYPT(pInput) NO-ERROR.
      
  pOut = BASE64-ENCODE(mMemPtr) NO-ERROR.
          
  RETURN "OK".
END.

FUNCTION {&Modul}-decrypt RETURN LONGCHAR(INPUT pInput AS LONGCHAR, INPUT pkey AS RAW).
  DEF VAR pOut AS LONGCHAR NO-UNDO.
  FIX-CODEPAGE(pOut) = "UTF-8".
  DEF VAR mMemPtrIn AS MEMPTR NO-UNDO.
  DEF VAR mMemPtrOut AS MEMPTR NO-UNDO.
  SECURITY-POLICY:SYMMETRIC-ENCRYPTION-ALGORITHM = "AES_CBC_256".
  SECURITY-POLICY:SYMMETRIC-ENCRYPTION-KEY = pkey.
  
  mMemPtrIn  = BASE64-DECODE(pInput) NO-ERROR.
  
  mMemPtrOut = DECRYPT(mMemPtrIn) NO-ERROR.
  
  COPY-LOB FROM mMemPtrOut TO pOut CONVERT SOURCE CODEPAGE "utf-8" NO-ERROR.
  
  SET-SIZE(mMemPtrIn) = 0.
  SET-SIZE(mMemPtrOut) = 0.
  RETURN pOut.
END.
Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
  • All those NO-ERROR decorations are hiding any reason of failure, remove them all. If in your actual code you are checking error-status:error or so, how errors are thrown can be vague, they will not set :error but do something else. – Stefan Drissen Dec 22 '20 at 16:30
  • As I said above, there is error handling in the actual code. In my experience, ERROR-STATUS with NO-ERROR will give the same results as a message thrown on the console. The software that I am preparing will run in batch mode and even in tests I cannot collect messages effectively. No offense, but I have checked it many times. Now I get accidentally "?" with no error with DECODE. – rgolinski Dec 22 '20 at 19:33
  • I had read your comment about skipping error handling and from my experience, how statements fail unfortunately can differ depending on the statement - see https://knowledgebase.progress.com/articles/Article/000022070 for example. Maybe a CATCH block can help. – Stefan Drissen Dec 23 '20 at 15:20

0 Answers0