Decrypt file from SAP app.server
Closed this issue · 2 comments
I have a requirement where I must decrypt a file that in SAP that has been encrypted with aes-256-cbc protocol. The file is encrypted with a fixed KEY and IV. I've already implemented all classes from this Git repo, test class also works fine so basically I'm ready to go. Unfortunately I haven't come to the point where I can start using the classes to really decrypt the data yet.
I'm able to decrypt the file via openSSL, so I'm sure it's possible to successfully decrypt the file. However, in ABAP I'm quite unsuccessful until now, probably because I'm completely new to encryption/decryption and still quite new to ABAP too. When I try to read the data from the file (file is placed on the app.server from where I should read it), I open a dataset in text mode with non-unicode encoding. I read the data into a variable lv_data which has type string (see code snippet below).
TRY.
OPEN DATASET lv_filepath FOR INPUT IN TEXT MODE ENCODING NON-UNICODE.
DO.
READ DATASET lv_filepath INTO lv_str.
IF sy-subrc NE 0.
EXIT.
ENDIF.
lv_data = |{ lv_data }{ lv_str }|.
ENDDO.
CATCH cx_root.
ENDTRY.
When I open the encrypted file with notepad it looks like this:
When the data is read into parameter lv_data (type string) in SAP it looks like this. Could it be that I'm messing something up with the data types?
Any help is much appreciated, thanks a lot in advance!
try opening the file IN BINARY MODE
, and load into a xstring
try opening the file
IN BINARY MODE
, and load into axstring
@larshp thanks a lot for this faster than lightning reply! 👍 That was the solution! I had already implemented the rest of the code so I was already able to see that the file was correctly decrypted with help of the AES-classes now. Thanks a lot for helping this girl out!