Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Encryption / Decryption of Abap Code

Former Member
0 Likes
3,642

Hi,

How to Encrypt & Decrypt ABAP code.

Thanks in Advance,

Sarath

7 REPLIES 7
Read only

Former Member
0 Likes
1,702

Could you please let us know your requirement for which you want to encript and decript your abap code.

Read only

0 Likes
1,702

Hi,

The requirement is we have developed as code with lots of effort for a very rare requirement.

So we want to avoid any taking a copy of the code form our developemnt server. This code will not be moved to production server at all.

Thanks In advance,

Sarath

Read only

Former Member
0 Likes
1,702

Use the following FM to encrypt

CALL FUNCTION 'FIEB_PASSWORD_ENCRYPT'

Use the following FM to decrypt

CALL FUNCTION 'FIEB_PASSWORD_DECRYPT'

By these FM you can encrypt & decrypt any fields of the Program.

Two more things:

1. You can't use these FM to decode user passwords.

2. Although their import parameters are case sensitive, when you test them from se37, the import parameters are converted to uppercase (thus, it may seem that they aren't working). A suggestion: encapsulate them in a custom FM that receives a string to be encrytped/decrypted and a parameter that says if you want to encrypt or decrypt and call this fm from your program. Test them very carefully, because once the string has been encrypted the decryption side is the only way to get it back.

function zsecurtext.

*"----


""Interfase local

*" IMPORTING

*" REFERENCE(INTEXT) TYPE FIEB_DECRYPTED_PASSWD OPTIONAL

*" REFERENCE(ENCRYPT) TYPE C OPTIONAL

*" EXPORTING

*" REFERENCE(OUTTEXT) TYPE FIEB_DECRYPTED_PASSWD

*"----


    • NOTE: This code doesn't work if run from se37. You should

    • encrypt

if encrypt = 'X'.

call function 'FIEB_PASSWORD_ENCRYPT'

exporting

im_decrypted_password = intext

importing

ex_encrypted_password = outtext.

else.

                • Decrypting *******************

call function 'FIEB_PASSWORD_DECRYPT'

exporting

im_encrypted_password = intext

importing

ex_decrypted_password = outtext.

endif.

endfunction.

Reward points if useful.

Read only

former_member189059
Active Contributor
0 Likes
1,702

Hello Sharath,

You can try this code to encrypt a program

But be careful, since its not possible to decrypt it

You will need to backup the code in some text file

the program can be run in hidden mode, but you cannot see its source



*&---------------------------------------------------------------------*
*& Report  ZHIDER
*&
*&---------------------------------------------------------------------*
*& Report           :      ZHIDER
*& Category         :      Offline
*& Business Analyst :      Technical Solution Group
*& Developed By     :      Kris Donald
*& Start Date       :      22-03-2007
*& End Date         :      22-03-2007
*&---------------------------------------------------------------------*
report  ZHIDER.


selection-screen begin of block b1 with frame title lv_frttl.
  parameters: p_prog like sy-repid obligatory.
selection-screen end of block b1.

data: gt_code(255)  type c occurs 0,
      gv_code      like line of gt_code,
      gt_code2(255) type c occurs 0.

initialization.
* sets the value for the title of the parameters block
  lv_frttl = 'Parameter'.

start-of-selection.

  read report p_prog into gt_code.
  if sy-subrc <> 0.
    write:/ 'Report does not exist'.
    exit.
  endif.

  append '*@#@@[SAP]' to gt_code2.
  loop at gt_code into gv_code.
    append gv_code to gt_code2.
  endloop.

  insert report p_prog from gt_code2.

* print unhidden source code for backup issues
  loop at gt_code into gv_code.
    write: / gv_code.
  endloop. "LOOP AT gt_code INTO gv_code

Read only

Former Member
0 Likes
1,702

Hi Sharath,

Im not 100% sure, but maybe FM "VRM_COMPUTE_MD5" will do the encrypting-job.

cheers,

Hema.

Read only

Former Member
0 Likes
1,702

One way of achieving it is to put your code into a Text file let's say "Code.txt".

Selection screen Parameters values into another text file. Let's say "Param.txt".

Write a driver program that will read both these files and dynamically creaes the program for your functionality as in "code.txt" and display the result and then deletes the dynamically created program.

Example : CODE.TXT - Origial functionality

Report zrg_ag.

Parameter: p1 type c,

P2 type c.

Write: p1, p2.

Text file containing selection screen Parameter, PARAM.TXT

A

B

Driver program to read both of the above files

&----


*& Report ZZZ_DEL_TEST_RG

*&

&----


*&

*&

&----


REPORT ZZZ_DEL_TEST_RG.

data: begin of code occurs 0,

text(255),

end of code.

data: begin of param occurs 0,

text(10),

end of param.

data: p1 type c,

p2 type c.

parameters: p_code like rlgrap-filename,

p_par like rlgrap-filename.

  • Upload "CODE.TXT" into an internal table

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = p_code

FILETYPE = 'DAT'

TABLES

DATA_TAB = code

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

NO_AUTHORITY = 10

OTHERS = 11.

  • Upload PARAM.TXT into an internal table

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = p_par

FILETYPE = 'DAT'

TABLES

DATA_TAB = param

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

NO_AUTHORITY = 10

OTHERS = 11.

insert report 'zrg_ag' from code.

  • Read selection screen parameters

read table param index 1.

p1 = param-text.

read table param index 2.

p2 = param-text.

submit zrg_ag with p1 = p1

with p2 = p2

and return.

delete report 'zrg_ag'.

REWARD IF USEFUL.

Read only

Former Member
0 Likes
1,702

Hi,

I also got the same type of requirement. Say Ex: We have developed a tool and we deployed it to the customer. We dont want to get that displayed. If it is not able to make invisible at leaset want to make the code in encrypted format. But te code should be executable.

Any suggestions ?