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

Operations on Text File - Encrypt, Decrypt, Password Protected

Former Member
0 Likes
2,001

Dear Experts,

My requirement is to upload a text file and do some operations on it and then encrypt the content in it ans save it on application server with password protected. Later i want to decrypt it.

Please help me for the following:

How to encyypt and decrypt the text file using standard encryption alogrithms like DES, MD5, RSA? Are there any standand function modules for both encryption and decryption which accepts a user defined public key?

How to download a password protected text file?

Thanks in advance.

6 REPLIES 6
Read only

Former Member
0 Likes
1,055

We do Encryption and Decryption all the time, but we use UNIX Commands in our ABAP programs to do it.

Read only

0 Likes
1,055

Thanks Richard...

Can u explain more clear with the help of an example....

Read only

0 Likes
1,055

Hello carry out the flllowing steps

1. Create corrosponding ECC command for unix one sm69 ( Use the command to encript the file and decript the file)

2. Write you file to AS

3.Perform the command ie. operation on the file using function module SXPG_COMMAND_EXECUTE on AS ( as you want..! passing paraeter will be your file name...so on and so forth )...Check more for function module documentation

Hope this helps..!

Read only

0 Likes
1,055

Dear Experts,

Please explain with the help of an example...

What are the commands to be used to encrypt/decrypt a file?

What do u mean by write file to AS?

Please explain with example....

Read only

Former Member
0 Likes
1,055

CALL FUNCTION 'Z_CRYPT_FILE'

EXPORTING

SOURCE_PATH = WS_PATH

SOURCE_FILE = WS_OLDFILE

DESTINATION_PATH = WS_NEW_PATH

DESTINATION_FILE = WS_NEWFILE

SWITCH = 'E'

KEY = ZUSER_PW

KEEP_SOURCE_FILE = ' '

EXCEPTIONS

INVALID_SWITCH = 1

SOURCE_FILE_NOTFOUND = 2

DIDNT_WORK = 3.

FUNCTION MODULE Z_CRYPT_FILE

DATA: CINPUT(300) TYPE C.

DATA: BEGIN OF LIST OCCURS 0,

DATA(238) TYPE C,

DELIMITER(04) TYPE C,

FILE(12) TYPE C,

END OF LIST.

DATA: SOURCE TYPE ZCHAR200.

DATA: DESTINATION TYPE ZCHAR200.

DATA: ZINDX TYPE I.

DATA: msg(100).

IF SWITCH = 'E'.

IF FILETYPE = 'T'.

OPEN DATASET SOURCE IN TEXT MODE FOR INPUT ENCODING DEFAULT

message msg.

ELSE.

OPEN DATASET SOURCE IN BINARY MODE FOR INPUT message msg.

ENDIF.

IF SY-SUBRC <> 0.

RAISE SOURCE_FILE_NOTFOUND.

ENDIF.

CLOSE DATASET SOURCE.

CLEAR CINPUT.

CONCATENATE '/usr/local/bin/gpg -sev -r'

KEY

'-o'

DESTINATION

SOURCE

INTO CINPUT SEPARATED BY SPACE.

CONCATENATE CINPUT '2>&1' INTO CINPUT SEPARATED BY ' '.

CALL 'SYSTEM' ID 'COMMAND' FIELD CINPUT ID 'TAB' FIELD

LIST-SYS.

IF FILETYPE = 'T'.

OPEN DATASET DESTINATION IN TEXT MODE FOR INPUT ENCODING DEFAULT

message msg.

ELSE.

OPEN DATASET DESTINATION IN BINARY MODE FOR INPUT message msg.

ENDIF.

IF SY-SUBRC = 0.

CLOSE DATASET DESTINATION.

IF keep_source_file <> 'X'.

CLEAR CINPUT.

CONCATENATE 'rm' SOURCE INTO CINPUT

SEPARATED BY SPACE.

CALL 'SYSTEM' ID 'COMMAND' FIELD CINPUT ID 'TAB' FIELD

LIST-SYS.

ENDIF.

ELSE.

write: 'Encryption error on command: ',

cinput.

skip 1.

loop at list.

write: / LIST.

endloop.

RAISE DIDNT_WORK.

ENDIF.

IF FILETYPE = 'T'.

OPEN DATASET SOURCE IN TEXT MODE FOR INPUT ENCODING DEFAULT.

ELSE.

OPEN DATASET SOURCE IN BINARY MODE FOR INPUT.

ENDIF.

IF SY-SUBRC <> 0.

RAISE SOURCE_FILE_NOTFOUND.

ENDIF.

CLOSE DATASET SOURCE.

CLEAR CINPUT.

CONCATENATE '/usr/local/bin/gpg -o'

DESTINATION

SOURCE

INTO CINPUT SEPARATED BY SPACE.

CONCATENATE CINPUT '2>&1' INTO CINPUT SEPARATED BY ' '.

CALL 'SYSTEM' ID 'COMMAND' FIELD CINPUT ID 'TAB' FIELD

LIST-SYS.

  • REFRESH LIST.

  • CLEAR LIST.

IF FILETYPE = 'T'.

OPEN DATASET DESTINATION IN TEXT MODE FOR INPUT ENCODING DEFAULT.

ELSE.

OPEN DATASET DESTINATION IN BINARY MODE FOR INPUT.

ENDIF.

IF SY-SUBRC = 0.

CLOSE DATASET DESTINATION.

ELSE.

*list output if error

loop at list.

write: / LIST.

endloop.

RAISE DIDNT_WORK.

ENDIF.

ENDIF.

Read only

Former Member
0 Likes
1,055

Password protected use following FM

SXPG_COMMAND_EXECUTE'