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 and Decryption using public key in abap

ramesh_n8
Participant
0 Likes
5,371

Hi,

My requirement is encrypt the string using one public key as well as decrypt the cipher text to plain text using the same key in ABAP.

I already know the list of function modules:

1. SCRAMBLE_STRING

2. HTTP_SCRAMBLE

3. MD5_CALCULATE_HASH_FOR_CHAR

etc.......

I can encrypt the string into cipher text using one of the above function modules. But I can't to be decrypt the cipher text to plain text.

Important thing is I want to encrypt some public key and the same is used to decrypt the cipher text to plain text.

Kindly help for this experts....

Regards,

Ramesh N

1 ACCEPTED SOLUTION
Read only

JK
Contributor
2,724

Hi Ramesh

interesting Topic 🙂

i did encryption/decryption  with private/public key (including signing) some time ago by using the functions of

sap Standard Report SSF01 (yes i know strange Name for a Report)

Example Encryption:

* do encryption call   CALL FUNCTION 'SSF_KRN_ENVELOPE'   
EXPORTING       ssftoolkit                   = space   
   str_format                   = 'PKCS7'   
   b_inenc                      = 'X'  
    io_spec                      = 'T' 
     ostr_input_data_l            = l_contentlen 
     str_pab                      = ssfpse   
   str_pab_password             = space 
   IMPORTING       ostr_enveloped_data_l        = l_contentenclen  
    crc                          = ssfrc  
  TABLES       ostr_input_data              = in_data_table
      recipient_list               = recip_list
      ostr_enveloped_data          = out_data_table 
   EXCEPTIONS       ssf_krn_error                = 399       ssf_krn_noop                 = 201       ssf_krn_nomemory             = 202       ssf_krn_opinv                = 203       ssf_krn_recipient_list_error = 207       ssf_krn_input_data_error     = 208       ssf_krn_invalid_par          = 209       ssf_krn_invalid_parlen       = 210       ssf_fb_input_parameter_error = 211       OTHERS                       = 212.

do decryption call

* fill recipient parameter
  CLEAR l_recip.   l_recip-id = ssfid.
  REFRESH recip_list.
  APPEND l_recip TO recip_list.
  CALL FUNCTION 'SSF_KRN_DEVELOPE'
    EXPORTING       SSFTOOLKIT                   = space   
   STR_FORMAT                   = 'PKCS7'      
B_OUTDEC                     = 'X'  
    IO_SPEC                      = 'T'  
    OSTR_ENVELOPED_DATA_L        = l_contentlen
    IMPORTING       OSTR_OUTPUT_DATA_L           = l_contentenclen   
   CRC                          = SSFRC     TABLES  
    OSTR_ENVELOPED_DATA          = IN_DATA_TABLE   
   RECIPIENT                    = RECIP_LIST 
     OSTR_OUTPUT_DATA             = OUT_DATA_TABLE
    EXCEPTIONS       SSF_KRN_ERROR                = 399       SSF_KRN_NOOP                 = 201       SSF_KRN_NOMEMORY             = 202       SSF_KRN_OPINV                = 203       SSF_KRN_RECIPIENT_ERROR      = 206       SSF_KRN_INPUT_DATA_ERROR     = 208       SSF_KRN_INVALID_PAR          = 209       SSF_KRN_INVALID_PARLEN       = 210       SSF_FB_INPUT_PARAMETER_ERROR = 211       OTHERS                       = 212.

if you give me some time i can write a more detailled blog about this functions

5 REPLIES 5
Read only

JK
Contributor
2,725

Hi Ramesh

interesting Topic 🙂

i did encryption/decryption  with private/public key (including signing) some time ago by using the functions of

sap Standard Report SSF01 (yes i know strange Name for a Report)

Example Encryption:

* do encryption call   CALL FUNCTION 'SSF_KRN_ENVELOPE'   
EXPORTING       ssftoolkit                   = space   
   str_format                   = 'PKCS7'   
   b_inenc                      = 'X'  
    io_spec                      = 'T' 
     ostr_input_data_l            = l_contentlen 
     str_pab                      = ssfpse   
   str_pab_password             = space 
   IMPORTING       ostr_enveloped_data_l        = l_contentenclen  
    crc                          = ssfrc  
  TABLES       ostr_input_data              = in_data_table
      recipient_list               = recip_list
      ostr_enveloped_data          = out_data_table 
   EXCEPTIONS       ssf_krn_error                = 399       ssf_krn_noop                 = 201       ssf_krn_nomemory             = 202       ssf_krn_opinv                = 203       ssf_krn_recipient_list_error = 207       ssf_krn_input_data_error     = 208       ssf_krn_invalid_par          = 209       ssf_krn_invalid_parlen       = 210       ssf_fb_input_parameter_error = 211       OTHERS                       = 212.

do decryption call

* fill recipient parameter
  CLEAR l_recip.   l_recip-id = ssfid.
  REFRESH recip_list.
  APPEND l_recip TO recip_list.
  CALL FUNCTION 'SSF_KRN_DEVELOPE'
    EXPORTING       SSFTOOLKIT                   = space   
   STR_FORMAT                   = 'PKCS7'      
B_OUTDEC                     = 'X'  
    IO_SPEC                      = 'T'  
    OSTR_ENVELOPED_DATA_L        = l_contentlen
    IMPORTING       OSTR_OUTPUT_DATA_L           = l_contentenclen   
   CRC                          = SSFRC     TABLES  
    OSTR_ENVELOPED_DATA          = IN_DATA_TABLE   
   RECIPIENT                    = RECIP_LIST 
     OSTR_OUTPUT_DATA             = OUT_DATA_TABLE
    EXCEPTIONS       SSF_KRN_ERROR                = 399       SSF_KRN_NOOP                 = 201       SSF_KRN_NOMEMORY             = 202       SSF_KRN_OPINV                = 203       SSF_KRN_RECIPIENT_ERROR      = 206       SSF_KRN_INPUT_DATA_ERROR     = 208       SSF_KRN_INVALID_PAR          = 209       SSF_KRN_INVALID_PARLEN       = 210       SSF_FB_INPUT_PARAMETER_ERROR = 211       OTHERS                       = 212.

if you give me some time i can write a more detailled blog about this functions

Read only

0 Likes
2,724

Hi Jorg,

     Thanks for your valuable reply. Kindly let me know if any other function modules or any other way to achieve the encryption and decryption in ABAP.

     I'm also searching the ways to achieve the same in ABAP .

Regards,

Ramesh N

Read only

Former Member
0 Likes
2,724

Hi

I have requirement to create password protected pdf ( I have pdf in binary ,XML,xstring format)

Read only

0 Likes
2,724

Hi Ramesh,

Were you finally able to achieve this outcome?

I am also looking at such a solution to encrypt /decrypt using public key.

Read only

0 Likes
2,724

Hi sagnik411,

resolve your issue ?